Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -96,8 +97,14 @@ public Sql[] generateSql(CreateJsonIndexStatement statement, Database database,
}

protected void handleJsonIndex(final CreateJsonIndexStatement statement, final Database database, final StringBuilder builder) {
if (database instanceof PostgresDatabase) {
if (database instanceof CockroachDatabase) {
builder.append(" USING gin (");
builder.append(Arrays.stream(statement.getColumns()).map(JsonEnabledColumnConfig.class::cast)
.map(c -> "(" + 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(", ")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ public MapJpaLiquibaseUpdaterProvider(KeycloakSession session) {

@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
Expand Down Expand Up @@ -113,6 +117,12 @@ protected void updateChangeSet(Liquibase liquibase) throws LiquibaseException, S

@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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- format of id of changeSet: client-scopes-${org.keycloak.models.map.storage.jpa.Constants.SUPPORTED_VERSION_CLIENT_SCOPE} -->
<!-- format of id of changeSet: client-scopes-${org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_CLIENT_SCOPE} -->
<changeSet author="keycloak" id="client-scopes-1">

<createTable tableName="client_scope">
Expand Down Expand Up @@ -64,7 +64,7 @@ limitations under the License.
<column name="name"/>
<column name="VALUE(255)" valueComputed="VALUE(255)"/>
</createIndex>
<modifySql dbms="postgresql">
<modifySql dbms="postgresql,cockroachdb">
<replace replace="VALUE(255)" with="(value::varchar(250))"/>
</modifySql>
</changeSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- format of id of changeSet: clients-${org.keycloak.models.map.storage.jpa.Constants.SUPPORTED_VERSION_CLIENT} -->
<!-- format of id of changeSet: clients-${org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_CLIENT} -->
<changeSet author="keycloak" id="clients-1">

<createTable tableName="client">
Expand Down Expand Up @@ -71,7 +71,7 @@ limitations under the License.
<column name="name"/>
<column name="VALUE(255)" valueComputed="VALUE(255)"/>
</createIndex>
<modifySql dbms="postgresql">
<modifySql dbms="postgresql,cockroachdb">
<replace replace="VALUE(255)" with="(value::varchar(250))"/>
</modifySql>
</changeSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<!-- format of id of changeSet: roles-${org.keycloak.models.map.storage.jpa.Constants.SUPPORTED_VERSION_ROLE} -->
<!-- format of id of changeSet: roles-${org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_ROLE} -->
<changeSet author="keycloak" id="roles-1">

<createTable tableName="role">
Expand Down Expand Up @@ -73,7 +73,7 @@ limitations under the License.
<column name="name"/>
<column name="VALUE(255)" valueComputed="VALUE(255)"/>
</createIndex>
<modifySql dbms="postgresql">
<modifySql dbms="postgresql,cockroachdb">
<replace replace="VALUE(255)" with="(value::varchar(250))"/>
</modifySql>
</changeSet>
Expand Down