diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/extension/CreateJsonIndexGenerator.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/extension/CreateJsonIndexGenerator.java index d08a4bde6b..137a6054af 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/extension/CreateJsonIndexGenerator.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/extension/CreateJsonIndexGenerator.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.stream.Collectors; import liquibase.database.Database; +import liquibase.database.core.CockroachDatabase; import liquibase.database.core.PostgresDatabase; import liquibase.exception.ValidationErrors; import liquibase.sql.Sql; @@ -96,8 +97,14 @@ public class CreateJsonIndexGenerator extends AbstractSqlGenerator "(" + c.getJsonColumn() + "->'" + c.getJsonProperty() + "')") + .collect(Collectors.joining(", "))) + .append(")"); + } + else if (database instanceof PostgresDatabase) { builder.append(" USING gin ("); builder.append(Arrays.stream(statement.getColumns()).map(JsonEnabledColumnConfig.class::cast) .map(c -> "(" + c.getJsonColumn() + "->'" + c.getJsonProperty() + "') jsonb_path_ops") .collect(Collectors.joining(", "))) diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/updater/MapJpaLiquibaseUpdaterProvider.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/updater/MapJpaLiquibaseUpdaterProvider.java index b23a1b20d1..8f95787bb9 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/updater/MapJpaLiquibaseUpdaterProvider.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/liquibase/updater/MapJpaLiquibaseUpdaterProvider.java @@ -49,15 +49,19 @@ public class MapJpaLiquibaseUpdaterProvider implements MapJpaUpdaterProvider { @Override public void update(Class modelType, Connection connection, String defaultSchema) { - update(modelType, connection, null, defaultSchema); + synchronized (MapJpaLiquibaseUpdaterProvider.class) { + this.updateSynch(modelType, connection, null, defaultSchema); + } } @Override public void export(Class modelType, Connection connection, String defaultSchema, File file) { - update(modelType, connection, file, defaultSchema); + synchronized (MapJpaLiquibaseUpdaterProvider.class) { + this.updateSynch(modelType, connection, file, defaultSchema); + } } - private void update(Class modelType, Connection connection, File file, String defaultSchema) { + protected void updateSynch(Class modelType, Connection connection, File file, String defaultSchema) { logger.debug("Starting database update"); // Need ThreadLocal as liquibase doesn't seem to have API to inject custom objects into tasks @@ -113,6 +117,12 @@ public class MapJpaLiquibaseUpdaterProvider implements MapJpaUpdaterProvider { @Override public Status validate(Class modelType, Connection connection, String defaultSchema) { + synchronized (MapJpaLiquibaseUpdaterProvider.class) { + return this.validateSynch(modelType, connection, defaultSchema); + } + } + + protected Status validateSynch(final Class modelType, final Connection connection, final String defaultSchema) { logger.debug("Validating if database is updated"); ThreadLocalSessionContext.setCurrentSession(session); diff --git a/model/map-jpa/src/main/resources/META-INF/client-scopes/jpa-client-scopes-changelog-1.xml b/model/map-jpa/src/main/resources/META-INF/client-scopes/jpa-client-scopes-changelog-1.xml index a07f0e2d3c..235fbba98e 100644 --- a/model/map-jpa/src/main/resources/META-INF/client-scopes/jpa-client-scopes-changelog-1.xml +++ b/model/map-jpa/src/main/resources/META-INF/client-scopes/jpa-client-scopes-changelog-1.xml @@ -22,7 +22,7 @@ limitations under the License. xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> - + @@ -64,7 +64,7 @@ limitations under the License. - + diff --git a/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml b/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml index ba0512b5a8..f758bdcf66 100644 --- a/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml +++ b/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml @@ -22,7 +22,7 @@ limitations under the License. xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> - + @@ -71,7 +71,7 @@ limitations under the License. - + diff --git a/model/map-jpa/src/main/resources/META-INF/roles/jpa-roles-changelog-1.xml b/model/map-jpa/src/main/resources/META-INF/roles/jpa-roles-changelog-1.xml index ec127ee578..c53af98108 100644 --- a/model/map-jpa/src/main/resources/META-INF/roles/jpa-roles-changelog-1.xml +++ b/model/map-jpa/src/main/resources/META-INF/roles/jpa-roles-changelog-1.xml @@ -22,7 +22,7 @@ limitations under the License. xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> - + @@ -73,7 +73,7 @@ limitations under the License. - +