Minor fixes. Flyway migration paths now prefer slashes to dots. Add Flyway version to 'info' command.

This commit is contained in:
Tim Donohue
2020-09-14 09:37:06 -05:00
parent a2cfa09c01
commit ae7ef8577b
2 changed files with 16 additions and 9 deletions

View File

@@ -39,6 +39,7 @@ import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.callback.Callback; import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.configuration.FluentConfiguration; import org.flywaydb.core.api.configuration.FluentConfiguration;
import org.flywaydb.core.internal.info.MigrationInfoDumper; import org.flywaydb.core.internal.info.MigrationInfoDumper;
import org.flywaydb.core.internal.license.VersionPrinter;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SingleConnectionDataSource; import org.springframework.jdbc.datasource.SingleConnectionDataSource;
@@ -74,6 +75,9 @@ public class DatabaseUtils {
public static final String DBMS_ORACLE = "oracle"; public static final String DBMS_ORACLE = "oracle";
public static final String DBMS_H2 = "h2"; public static final String DBMS_H2 = "h2";
// Name of the table that Flyway uses for its migration history
public static final String FLYWAY_TABLE = "schema_version";
/** /**
* Default constructor * Default constructor
*/ */
@@ -412,6 +416,8 @@ public class DatabaseUtils {
"PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension installed/up-to-date? " + pgcryptoUpToDate + "" + "PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension installed/up-to-date? " + pgcryptoUpToDate + "" +
" " + ((pgcryptoVersion != null) ? "(version=" + pgcryptoVersion + ")" : "(not installed)")); " " + ((pgcryptoVersion != null) ? "(version=" + pgcryptoVersion + ")" : "(not installed)"));
} }
// Finally, print out our version of Flyway
System.out.println("FlywayDB Version: " + VersionPrinter.getVersion());
} }
/** /**
@@ -530,20 +536,21 @@ public class DatabaseUtils {
// Determine location(s) where Flyway will load all DB migrations // Determine location(s) where Flyway will load all DB migrations
ArrayList<String> scriptLocations = new ArrayList<>(); ArrayList<String> scriptLocations = new ArrayList<>();
// First, add location for custom SQL migrations, if any (based on DB Type) // First, add location for custom SQL migrations, if exists (based on DB Type)
// e.g. [dspace.dir]/etc/[dbtype]/ // e.g. [dspace.dir]/etc/[dbtype]/
// (We skip this for H2 as it's only used for unit testing) // (We skip this for H2 as it's only used for unit testing)
if (!dbType.equals(DBMS_H2)) { String etcDirPath = config.getProperty("dspace.dir") + "/etc/" + dbType;
scriptLocations.add("filesystem:" + config.getProperty("dspace.dir") + File etcDir = new File(etcDirPath);
"/etc/" + dbType); if (etcDir.exists() && !dbType.equals(DBMS_H2)) {
scriptLocations.add("filesystem:" + etcDirPath);
} }
// Also add the Java package where Flyway will load SQL migrations from (based on DB Type) // Also add the Java package where Flyway will load SQL migrations from (based on DB Type)
scriptLocations.add("classpath:org.dspace.storage.rdbms.sqlmigration." + dbType); scriptLocations.add("classpath:org/dspace/storage/rdbms/sqlmigration/" + dbType);
// Also add the Java package where Flyway will load Java migrations from // Also add the Java package where Flyway will load Java migrations from
// NOTE: this also loads migrations from any sub-package // NOTE: this also loads migrations from any sub-package
scriptLocations.add("classpath:org.dspace.storage.rdbms.migration"); scriptLocations.add("classpath:org/dspace/storage/rdbms/migration");
//Add all potential workflow migration paths //Add all potential workflow migration paths
List<String> workflowFlywayMigrationLocations = WorkflowServiceFactory.getInstance() List<String> workflowFlywayMigrationLocations = WorkflowServiceFactory.getInstance()
@@ -567,7 +574,7 @@ public class DatabaseUtils {
// Tell Flyway to use the "schema_version" table in the database to manage its migration history // Tell Flyway to use the "schema_version" table in the database to manage its migration history
// As of Flyway v5, the default table is named "flyway_schema_history" // As of Flyway v5, the default table is named "flyway_schema_history"
// We are using the older name ("schema_version") for backwards compatibility. // We are using the older name ("schema_version") for backwards compatibility.
flywayConfiguration.table("schema_version"); flywayConfiguration.table(FLYWAY_TABLE);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unable to setup Flyway against DSpace database", e); log.error("Unable to setup Flyway against DSpace database", e);
} }
@@ -1347,7 +1354,7 @@ public class DatabaseUtils {
*/ */
public static String getCurrentFlywayState(Connection connection) throws SQLException { public static String getCurrentFlywayState(Connection connection) throws SQLException {
PreparedStatement statement = connection PreparedStatement statement = connection
.prepareStatement("SELECT \"version\" FROM \"schema_version\" ORDER BY \"version\" desc"); .prepareStatement("SELECT \"version\" FROM \"" + FLYWAY_TABLE + "\" ORDER BY \"version\" desc");
ResultSet resultSet = statement.executeQuery(); ResultSet resultSet = statement.executeQuery();
resultSet.next(); resultSet.next();
return resultSet.getString("version"); return resultSet.getString("version");

View File

@@ -188,7 +188,7 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
@Override @Override
public List<String> getFlywayMigrationLocations() { public List<String> getFlywayMigrationLocations() {
return Collections.singletonList("classpath:org.dspace.storage.rdbms.xmlworkflow"); return Collections.singletonList("classpath:org/dspace/storage/rdbms/xmlworkflow");
} }
@Override @Override