From a097644e5fc18c94ae94ebe0231e72ca20c13bc6 Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Fri, 23 Dec 2016 15:15:54 -0700 Subject: [PATCH] Created a better workaround for https://liquibase.jira.com/browse/CORE-2966 Signed-off-by: Andrew DeMaria --- .../spring/DbmsVersionPrecondition.java | 77 +++++++++++++++++++ .../player/spring/SpringLiquibase.java | 1 + .../resources/liquibase/legacy/schema32.xml | 2 +- .../resources/liquibase/legacy/schema47.xml | 23 +++++- .../resources/liquibase/legacy/schema53.xml | 21 +++++ 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/spring/DbmsVersionPrecondition.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/DbmsVersionPrecondition.java b/libresonic-main/src/main/java/org/libresonic/player/spring/DbmsVersionPrecondition.java new file mode 100644 index 00000000..0b16fc04 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/DbmsVersionPrecondition.java @@ -0,0 +1,77 @@ +package org.libresonic.player.spring; + +import liquibase.changelog.ChangeSet; +import liquibase.changelog.DatabaseChangeLog; +import liquibase.database.Database; +import liquibase.exception.PreconditionErrorException; +import liquibase.exception.PreconditionFailedException; +import liquibase.exception.ValidationErrors; +import liquibase.exception.Warnings; +import liquibase.precondition.Precondition; +import liquibase.serializer.AbstractLiquibaseSerializable; + +public class DbmsVersionPrecondition extends AbstractLiquibaseSerializable implements Precondition { + private Integer major; + private Integer minor; + + @Override + public String getName() { + return "dbmsVersion"; + } + + @Override + public Warnings warn(Database database) { + return new Warnings(); + } + + @Override + public ValidationErrors validate(Database database) { + return new ValidationErrors(); + } + + @Override + public void check( + Database database, DatabaseChangeLog changeLog, ChangeSet changeSet + ) throws PreconditionFailedException, PreconditionErrorException { + try { + int dbMajor = database.getDatabaseMajorVersion(); + int dbMinor = database.getDatabaseMinorVersion(); + if(major != null && !major.equals(dbMajor)) { + throw new PreconditionFailedException("DBMS Major Version Precondition failed: expected " + major + ", got " + dbMajor, changeLog, this); + } + if(minor != null && !minor.equals(dbMinor)) { + throw new PreconditionFailedException("DBMS Minor Version Precondition failed: expected " + minor + ", got " + dbMinor, changeLog, this); + } + } catch (PreconditionFailedException e) { + throw e; + } catch (Exception e) { + throw new PreconditionErrorException(e, changeLog, this); + } + } + + @Override + public String getSerializedObjectName() { + return getName(); + } + + @Override + public String getSerializedObjectNamespace() { + return GENERIC_CHANGELOG_EXTENSION_NAMESPACE; + } + + public Integer getMajor() { + return major; + } + + public void setMajor(Integer major) { + this.major = major; + } + + public Integer getMinor() { + return minor; + } + + public void setMinor(Integer minor) { + this.minor = minor; + } +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java b/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java index 0ff200b4..4eda164a 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java @@ -51,6 +51,7 @@ public class SpringLiquibase extends liquibase.integration.spring.SpringLiquibas if (StringUtils.trimToNull(this.defaultSchema) != null) { database.setDefaultSchemaName(this.defaultSchema); } + liquibase.precondition.PreconditionFactory.getInstance().register(DbmsVersionPrecondition.class); return database; } diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml index ee76a9a7..50d31ef6 100644 --- a/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml @@ -64,7 +64,7 @@ - 7:d968449010bf1de51dac5f300359b2c5 + 7:0d4fbe2adcca829c14d12a5b1a8229c5 diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml index b797459a..df3eb9f7 100644 --- a/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml @@ -153,7 +153,7 @@ - 7:c69a9ccadcb83d57684bb3b7aa34fb22 + 7:a3a788d87fd58508ecb4acac39e255c6 @@ -216,6 +216,12 @@ + + + + + + @@ -224,6 +230,21 @@ + + + + + + + + select count(*) from INFORMATION_SCHEMA.SYSTEM_INDEXINFO where + TABLE_NAME = 'album' and INDEX_NAME = 'idx_album_name'; + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml index 1a9f1a23..f8bad2fd 100644 --- a/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml @@ -17,6 +17,12 @@ + + + + + + @@ -25,6 +31,21 @@ + + + + + + + + select count(*) from INFORMATION_SCHEMA.SYSTEM_INDEXINFO where + TABLE_NAME = 'podcast_episode' and INDEX_NAME = 'idx_podcast_episode_url'; + + + + + +