From 5bc2137193d979404dee917c6f3f5789cb622946 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Sat, 15 Feb 2020 17:21:50 +0100 Subject: [PATCH] Use new Flyway API for configuring Flyway Former-commit-id: dce868915bc8c567f9eba5dd78e4c8d26a488be8 --- INSTALL.md | 4 +- .../org/libreccm/modules/CcmIntegrator.java | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 601ace908..5d82b40ea 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,7 +24,7 @@ wildfly please refer to the WildFly documentation following content: ``` - ?xml version="1.0" encoding="UTF-8"?> + @@ -64,7 +64,7 @@ wildfly please refer to the WildFly documentation 1. Start the JBOSS CLI tool: `bin/jboss-cli.sh` or `bin/jboss-cli.bat`. 2. Add new datasource: ``` - [standalone@localhost:9990 /] data-source add --name=scicms-devel --driver-name=postgresql --jndi-name=java:/comp/env/jdbc/scientificcms/db --connection-url=jdbc:postgresql://localhost:5432/scicms-devel --user-name=libreccm --password=libreccm + [standalone@localhost:9990 /] data-source add --name=librecms --driver-name=postgresql --jndi-name=java:/comp/env/jdbc/scientificcms/db --connection-url=jdbc:postgresql://localhost:5432/librecm --user-name=libreccm --password=libreccm ``` Replace the name of the datasource, the connection URL, diff --git a/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java b/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java index 94e14f245..d31eaa438 100644 --- a/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java +++ b/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java @@ -121,12 +121,15 @@ public class CcmIntegrator implements Integrator { //Migrate tables and sequences which don't belong to a module //for instance the hibernate_sequence - final Flyway flyway = new Flyway(); - flyway.setDataSource(dataSource); final StringBuffer buffer = new StringBuffer( "db/migrations/org/libreccm/base"); appendDbLocation(buffer, connection); - flyway.setLocations(buffer.toString()); + final Flyway flyway = Flyway + .configure() + .dataSource(dataSource) + .locations(buffer.toString()) + .load(); + flyway.migrate(); //Migrate the modules @@ -267,18 +270,19 @@ public class CcmIntegrator implements Integrator { moduleInfo.load(module); //Create a Flyway instance for the the module. - final Flyway flyway = new Flyway(); - flyway.setDataSource(dataSource); - //Set schema correctly for the different databases. Necessary because - //different RDBMS handle case different. + final String schema; if ("H2".equals(connection.getMetaData().getDatabaseProductName())) { - flyway.setSchemas(getSchemaName(moduleInfo).toUpperCase( - Locale.ROOT)); + schema = getSchemaName(moduleInfo).toUpperCase(Locale.ROOT); } else { - flyway.setSchemas(getSchemaName(moduleInfo)); + schema = getSchemaName(moduleInfo); } - flyway.setLocations(getLocation(moduleInfo, connection)); - + final Flyway flyway = Flyway + .configure() + .dataSource(dataSource) + .schemas(schema) + .locations(getLocation(moduleInfo, connection)) + .load(); + //Get current migrations info final MigrationInfo current = flyway.info().current(); boolean newModule; @@ -394,10 +398,12 @@ public class CcmIntegrator implements Integrator { throws SQLException { LOGGER.info("Removing schema for module %s...", module.getClass().getName()); - final Flyway flyway = new Flyway(); - flyway.setDataSource(dataSource); - flyway.setSchemas(getSchemaName(moduleInfo)); - flyway.setLocations(getLocation(moduleInfo, connection)); + final Flyway flyway = Flyway + .configure() + .dataSource(dataSource) + .schemas(getSchemaName(moduleInfo)) + .locations(getLocation(moduleInfo, connection)) + .load(); LOGGER.warn("Deleting schema for module {}...", moduleInfo.getModuleName()); flyway.clean();