Merge pull request #3319 from hmlnarik/KEYCLOAK-3588

KEYCLOAK-3588: DB up-to-date check should not modify DB
This commit is contained in:
Stian Thorgersen 2016-10-17 18:54:59 +02:00 committed by GitHub
commit 7c09b0c7b4

View file

@ -96,7 +96,7 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
protected void updateChangeSet(Liquibase liquibase, String changelog, File exportFile) throws LiquibaseException, IOException { protected void updateChangeSet(Liquibase liquibase, String changelog, File exportFile) throws LiquibaseException, IOException {
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets((Contexts) null, new LabelExpression()); List<ChangeSet> changeSets = getChangeSets(liquibase);
if (!changeSets.isEmpty()) { if (!changeSets.isEmpty()) {
List<RanChangeSet> ranChangeSets = liquibase.getDatabase().getRanChangeSetList(); List<RanChangeSet> ranChangeSets = liquibase.getDatabase().getRanChangeSetList();
if (ranChangeSets.isEmpty()) { if (ranChangeSets.isEmpty()) {
@ -160,7 +160,8 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
} }
protected Status validateChangeSet(Liquibase liquibase, String changelog) throws LiquibaseException { protected Status validateChangeSet(Liquibase liquibase, String changelog) throws LiquibaseException {
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets((Contexts) null, new LabelExpression()); List<ChangeSet> changeSets = getChangeSets(liquibase);
if (!changeSets.isEmpty()) { if (!changeSets.isEmpty()) {
if (changeSets.size() == liquibase.getDatabaseChangeLog().getChangeSets().size()) { if (changeSets.size() == liquibase.getDatabaseChangeLog().getChangeSets().size()) {
return Status.EMPTY; return Status.EMPTY;
@ -174,6 +175,14 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
} }
} }
@SuppressWarnings("unchecked")
private List<ChangeSet> getChangeSets(Liquibase liquibase) {
// TODO: When https://liquibase.jira.com/browse/CORE-2919 is resolved, replace the following two lines with:
// List<ChangeSet> changeSets = liquibase.listUnrunChangeSets((Contexts) null, new LabelExpression(), false);
Method listUnrunChangeSets = Reflections.findDeclaredMethod(Liquibase.class, "listUnrunChangeSets", Contexts.class, LabelExpression.class, boolean.class);
return Reflections.invokeMethod(true, listUnrunChangeSets, List.class, liquibase, (Contexts) null, new LabelExpression(), false);
}
private Liquibase getLiquibaseForKeycloakUpdate(Connection connection, String defaultSchema) throws LiquibaseException { private Liquibase getLiquibaseForKeycloakUpdate(Connection connection, String defaultSchema) throws LiquibaseException {
LiquibaseConnectionProvider liquibaseProvider = session.getProvider(LiquibaseConnectionProvider.class); LiquibaseConnectionProvider liquibaseProvider = session.getProvider(LiquibaseConnectionProvider.class);
return liquibaseProvider.getLiquibase(connection, defaultSchema); return liquibaseProvider.getLiquibase(connection, defaultSchema);