diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/AbstractUpgradeStatements.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/AbstractUpgradeStatements.java
new file mode 100644
index 00000000000..2c3ef60ebcc
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/AbstractUpgradeStatements.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+public abstract class AbstractUpgradeStatements implements UpgradeStatements {
+
+ protected String commonStatements() {
+ return """
+ INSERT INTO GroupTypeExtension SELECT * FROM TypeExtension;
+ INSERT INTO GroupTypeExtension_Class SELECT * FROM TypeExtension_AnyTypeClass;
+
+ DROP TABLE TypeExtension_AnyTypeClass;
+ DROP TABLE TypeExtension;
+ DROP TABLE SyncopeRole_DynRealm;
+ DROP TABLE DynRealmMembership;
+ DROP TABLE DynRealm;
+ DROP TABLE UDynGroupMembership;
+ DROP TABLE ADynGroupMembership;
+ DROP TABLE UDynGroupMembers;
+ DROP TABLE ADynGroupMembers;
+ DROP TABLE DynRoleMembers;
+ DROP TABLE DynRealmMembers;
+ """;
+ }
+}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
index 6de47930d2b..ecba0b63b27 100644
--- a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
@@ -38,9 +38,6 @@ public class GenerateUpgradeSQL {
UPDATE SyncopeGroup SET gManager_id=groupOwner_id;
ALTER TABLE SyncopeGroup DROP COLUMN groupOwner_id;
- INSERT INTO OIDCOpEntity SELECT id,json AS jwks,'{}' AS customScopes FROM OIDCJWKS;
- DROP TABLE OIDCJWKS;
-
DROP TABLE SyncopeRole_DynRealm;
DROP TABLE DynRealmMembership;
DROP TABLE DynRealm;
@@ -67,7 +64,11 @@ public void run(final Writer out) throws IOException, SQLException {
// run OpenJPA's SchemaTool to get the update statements
schemaTool.run();
- out.append('\n').append(INIT_SQL_STATEMENTS).append('\n');
+ UpgradeStatements statements = UpgradeStatementsFactory.forDatabase(jdbcConf.getDBDictionaryInstance());
+
+ out.append('\n');
+ out.append(statements.getStatements());
+ out.append('\n');
}
}
}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/MariaDBUpgradeStatements.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/MariaDBUpgradeStatements.java
new file mode 100644
index 00000000000..929ee418715
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/MariaDBUpgradeStatements.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+public class MariaDBUpgradeStatements extends AbstractUpgradeStatements {
+
+ @Override
+ public String getStatements() {
+
+ String mariaDBUpgradeStatements = """
+ UPDATE SyncopeGroup SET uManager_id=userOwner_id;
+
+ SET @fk_name = (
+ SELECT CONSTRAINT_NAME
+ FROM information_schema.KEY_COLUMN_USAGE
+ WHERE TABLE_SCHEMA = DATABASE()
+ AND TABLE_NAME = 'SyncopeGroup'
+ AND COLUMN_NAME = 'userOwner_id'
+ AND REFERENCED_TABLE_NAME IS NOT NULL
+ LIMIT 1
+ );
+
+ SET @sql = CONCAT('ALTER TABLE SyncopeGroup DROP FOREIGN KEY `', @fk_name, '`');
+ PREPARE stmt FROM @sql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+ ALTER TABLE SyncopeGroup DROP COLUMN userOwner_id;
+
+ UPDATE SyncopeGroup SET gManager_id=groupOwner_id;
+ SET @fk_name = (
+ SELECT CONSTRAINT_NAME
+ FROM information_schema.KEY_COLUMN_USAGE
+ WHERE TABLE_SCHEMA = DATABASE()
+ AND TABLE_NAME = 'SyncopeGroup'
+ AND COLUMN_NAME = 'groupOwner_id'
+ AND REFERENCED_TABLE_NAME IS NOT NULL
+ LIMIT 1
+ );
+
+ SET @sql = CONCAT('ALTER TABLE SyncopeGroup DROP FOREIGN KEY `', @fk_name, '`');
+ PREPARE stmt FROM @sql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+ ALTER TABLE SyncopeGroup DROP COLUMN groupOwner_id;
+
+ DELETE FROM AccessToken;
+ ALTER TABLE AccessToken MODIFY COLUMN authorities TEXT;
+
+ INSERT INTO OIDCOpEntity (id, jwks, customScopes)
+ SELECT id, json ,'{}'
+ FROM OIDCJWKS;
+
+ DROP TABLE OIDCJWKS;
+ """;
+
+ return commonStatements() + mariaDBUpgradeStatements;
+ }
+}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/MySQLUpgradeStatements.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/MySQLUpgradeStatements.java
new file mode 100644
index 00000000000..c9425cbc3bc
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/MySQLUpgradeStatements.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+public class MySQLUpgradeStatements extends AbstractUpgradeStatements {
+
+ @Override
+ public String getStatements() {
+
+ String mysqlUpgradeStatements = """
+ UPDATE SyncopeGroup SET uManager_id=userOwner_id;
+
+ SET @fk_name = (
+ SELECT CONSTRAINT_NAME
+ FROM information_schema.KEY_COLUMN_USAGE
+ WHERE TABLE_SCHEMA = DATABASE()
+ AND TABLE_NAME = 'SyncopeGroup'
+ AND COLUMN_NAME = 'userOwner_id'
+ AND REFERENCED_TABLE_NAME IS NOT NULL
+ LIMIT 1
+ );
+
+ SET @sql = CONCAT(
+ 'ALTER TABLE SyncopeGroup DROP FOREIGN KEY ',
+ @fk_name
+ );
+ PREPARE stmt FROM @sql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+ ALTER TABLE SyncopeGroup DROP COLUMN userOwner_id;
+
+ UPDATE SyncopeGroup SET gManager_id=groupOwner_id;
+ SET @fk_name = (
+ SELECT CONSTRAINT_NAME
+ FROM information_schema.KEY_COLUMN_USAGE
+ WHERE TABLE_SCHEMA = DATABASE()
+ AND TABLE_NAME = 'SyncopeGroup'
+ AND COLUMN_NAME = 'groupOwner_id'
+ AND REFERENCED_TABLE_NAME IS NOT NULL
+ LIMIT 1
+ );
+
+ SET @sql = CONCAT(
+ 'ALTER TABLE SyncopeGroup DROP FOREIGN KEY ',
+ @fk_name
+ );
+ PREPARE stmt FROM @sql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+ ALTER TABLE SyncopeGroup DROP COLUMN groupOwner_id;
+
+ DELETE FROM AccessToken;
+ ALTER TABLE AccessToken MODIFY COLUMN authorities TEXT;
+
+ INSERT INTO OIDCOpEntity (id, jwks, customScopes)
+ SELECT id, CAST(json AS BINARY) ,'{}'
+ FROM OIDCJWKS;
+
+ DROP TABLE OIDCJWKS;
+ """;
+
+ return commonStatements() + mysqlUpgradeStatements;
+ }
+}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/OracleUpgradeStatements.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/OracleUpgradeStatements.java
new file mode 100644
index 00000000000..5f524ee8a2d
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/OracleUpgradeStatements.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+public class OracleUpgradeStatements extends AbstractUpgradeStatements {
+
+ @Override
+ public String getStatements() {
+
+ String postgreSQLUpgradeStatements = """
+ UPDATE SyncopeGroup SET uManager_id=userOwner_id;
+ ALTER TABLE SyncopeGroup DROP COLUMN userOwner_id;
+
+ UPDATE SyncopeGroup SET gManager_id=groupOwner_id;
+ ALTER TABLE SyncopeGroup DROP COLUMN groupOwner_id;
+
+ DELETE FROM ACCESSTOKEN;
+ ALTER TABLE ACCESSTOKEN MODIFY AUTHORITIES CLOB;
+ INSERT INTO OIDCOpEntity (id, jwks, customScopes)
+ SELECT id, clob_to_blob(json),'{}' FROM OIDCJWKS;
+
+ DROP TABLE OIDCJWKS;
+ """;
+
+ return convertCLOBToBLOBFunction() + commonStatements() + postgreSQLUpgradeStatements;
+ }
+
+ private String convertCLOBToBLOBFunction() {
+ return """
+ CREATE OR REPLACE FUNCTION clob_to_blob(
+ p_clob IN CLOB
+ ) RETURN BLOB IS
+ l_blob BLOB;
+ l_dest_offset INTEGER := 1;
+ l_src_offset INTEGER := 1;
+ l_lang_ctx INTEGER := DBMS_LOB.DEFAULT_LANG_CTX;
+ l_warning INTEGER;
+ BEGIN
+ IF p_clob IS NULL THEN
+ RETURN NULL;
+ END IF;
+
+ DBMS_LOB.CREATETEMPORARY(l_blob, TRUE);
+
+ DBMS_LOB.CONVERTTOBLOB(
+ dest_lob => l_blob,
+ src_clob => p_clob,
+ amount => DBMS_LOB.LOBMAXSIZE,
+ dest_offset => l_dest_offset,
+ src_offset => l_src_offset,
+ blob_csid => NLS_CHARSET_ID('AL32UTF8'),
+ lang_context => l_lang_ctx,
+ warning => l_warning
+ );
+
+ RETURN l_blob;
+ END;
+
+ """;
+ }
+}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/PostgreSQLUpgradeStatements.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/PostgreSQLUpgradeStatements.java
new file mode 100644
index 00000000000..417de714392
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/PostgreSQLUpgradeStatements.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+public class PostgreSQLUpgradeStatements extends AbstractUpgradeStatements {
+
+ @Override
+ public String getStatements() {
+
+ String postgreSQLUpgradeStatements = """
+ UPDATE SyncopeGroup SET uManager_id=userOwner_id;
+ ALTER TABLE SyncopeGroup DROP COLUMN userOwner_id;
+
+ UPDATE SyncopeGroup SET gManager_id=groupOwner_id;
+ ALTER TABLE SyncopeGroup DROP COLUMN groupOwner_id;
+
+ DELETE FROM AccessToken;
+ ALTER TABLE AccessToken ALTER COLUMN authorities TYPE TEXT;
+ INSERT INTO OIDCOpEntity (id, jwks, customScopes)
+ SELECT id,convert_to(json, 'UTF-8') AS jwks,'{}' AS customScopes FROM OIDCJWKS;
+
+ DROP TABLE OIDCJWKS;
+ """;
+
+ return commonStatements() + postgreSQLUpgradeStatements;
+ }
+}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/UpgradeStatements.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/UpgradeStatements.java
new file mode 100644
index 00000000000..4c7b7bf8461
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/UpgradeStatements.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+public interface UpgradeStatements {
+
+ String getStatements();
+}
diff --git a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/UpgradeStatementsFactory.java b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/UpgradeStatementsFactory.java
new file mode 100644
index 00000000000..dce3d268447
--- /dev/null
+++ b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/UpgradeStatementsFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.upgrade;
+
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.MariaDBDictionary;
+import org.apache.openjpa.jdbc.sql.MySQLDictionary;
+import org.apache.openjpa.jdbc.sql.OracleDictionary;
+import org.apache.openjpa.jdbc.sql.PostgresDictionary;
+
+public final class UpgradeStatementsFactory {
+
+ private UpgradeStatementsFactory() {
+ }
+
+ public static UpgradeStatements forDatabase(final DBDictionary dictionary) {
+
+ if (dictionary instanceof PostgresDictionary) {
+ return new PostgreSQLUpgradeStatements();
+ }
+ if (dictionary instanceof MySQLDictionary) {
+ return new MySQLUpgradeStatements();
+ }
+ if (dictionary instanceof MariaDBDictionary) {
+ return new MariaDBUpgradeStatements();
+ }
+ if (dictionary instanceof OracleDictionary) {
+ return new OracleUpgradeStatements();
+ }
+
+ throw new IllegalArgumentException(dictionary.platform);
+ }
+}
diff --git a/core/persistence-jpa-upgrader/src/main/resources/schema-mariadb.xml b/core/persistence-jpa-upgrader/src/main/resources/schema-mariadb.xml
index 25aa8bbebd1..f2e5fa8aa02 100644
--- a/core/persistence-jpa-upgrader/src/main/resources/schema-mariadb.xml
+++ b/core/persistence-jpa-upgrader/src/main/resources/schema-mariadb.xml
@@ -62,7 +62,7 @@ under the License.