KEYCLOAK-1530 Ability to specify default database schema

This commit is contained in:
Stian Thorgersen 2015-07-14 14:33:45 +02:00
parent 66373ccab2
commit 4e538dd138
4 changed files with 10 additions and 6 deletions

View file

@ -46,8 +46,8 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
private static final String CHANGELOG = "META-INF/jpa-changelog-master.xml";
@Override
public String getCurrentVersionSql() {
return "SELECT ID from DATABASECHANGELOG ORDER BY DATEEXECUTED DESC LIMIT 1";
public String getCurrentVersionSql(String defaultSchema) {
return "SELECT ID from " + getTable("DATABASECHANGELOG", defaultSchema) + " ORDER BY DATEEXECUTED DESC LIMIT 1";
}
@Override
@ -65,7 +65,7 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
if (changeSets.get(0).getId().equals(FIRST_VERSION)) {
Statement statement = connection.createStatement();
try {
statement.executeQuery("SELECT id FROM REALM");
statement.executeQuery("SELECT id FROM " + getTable("REALM", defaultSchema));
logger.infov("Updating database from {0} to {1}", FIRST_VERSION, changeSets.get(changeSets.size() - 1).getId());
liquibase.markNextChangeSetRan(null);
@ -231,4 +231,8 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
}
private String getTable(String table, String defaultSchema) {
return defaultSchema != null ? defaultSchema + "." + table : table;
}
}

View file

@ -133,7 +133,7 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
if (databaseSchema.equals("update")) {
String currentVersion = null;
try {
ResultSet resultSet = connection.createStatement().executeQuery(updater.getCurrentVersionSql());
ResultSet resultSet = connection.createStatement().executeQuery(updater.getCurrentVersionSql(schema));
if (resultSet.next()) {
currentVersion = resultSet.getString(1);
}

View file

@ -14,7 +14,7 @@ public interface JpaUpdaterProvider extends Provider {
public String LAST_VERSION = "1.4.0";
public String getCurrentVersionSql();
public String getCurrentVersionSql(String defaultSchema);
public void update(KeycloakSession session, Connection connection, String defaultSchema);

View file

@ -196,7 +196,7 @@
<term>schema</term>
<listitem>
<para>
Specify the default database schema to use
Specify the database schema to use
</para>
</listitem>
</varlistentry>