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"; private static final String CHANGELOG = "META-INF/jpa-changelog-master.xml";
@Override @Override
public String getCurrentVersionSql() { public String getCurrentVersionSql(String defaultSchema) {
return "SELECT ID from DATABASECHANGELOG ORDER BY DATEEXECUTED DESC LIMIT 1"; return "SELECT ID from " + getTable("DATABASECHANGELOG", defaultSchema) + " ORDER BY DATEEXECUTED DESC LIMIT 1";
} }
@Override @Override
@ -65,7 +65,7 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
if (changeSets.get(0).getId().equals(FIRST_VERSION)) { if (changeSets.get(0).getId().equals(FIRST_VERSION)) {
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
try { 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()); logger.infov("Updating database from {0} to {1}", FIRST_VERSION, changeSets.get(changeSets.size() - 1).getId());
liquibase.markNextChangeSetRan(null); 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")) { if (databaseSchema.equals("update")) {
String currentVersion = null; String currentVersion = null;
try { try {
ResultSet resultSet = connection.createStatement().executeQuery(updater.getCurrentVersionSql()); ResultSet resultSet = connection.createStatement().executeQuery(updater.getCurrentVersionSql(schema));
if (resultSet.next()) { if (resultSet.next()) {
currentVersion = resultSet.getString(1); currentVersion = resultSet.getString(1);
} }

View file

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

View file

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