Use new Flyway API for configuring Flyway

Former-commit-id: dce868915b
pull/2/head
Jens Pelzetter 2020-02-15 17:21:50 +01:00
parent d0d79ccc95
commit 5bc2137193
2 changed files with 24 additions and 18 deletions

View File

@ -24,7 +24,7 @@ wildfly please refer to the WildFly documentation
following content:
```
?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.10.jar"/>
@ -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,

View File

@ -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,17 +270,18 @@ 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();
@ -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();