-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
252 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
description = 'jPOS-EE :: flyWay support' | ||
|
||
dependencies { | ||
compile project(':modules:dbsupport') | ||
compile project(':modules:db-postgresql') | ||
compile project(':modules:logback') | ||
compile libraries.flywaydb | ||
} | ||
|
||
apply from: "${rootProject.projectDir}/jpos-app.gradle" | ||
|
63 changes: 63 additions & 0 deletions
63
modules/db-flyway/src/main/java/org/jpos/flyway/FlywaySupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.jpos.flyway; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.configuration.FluentConfiguration; | ||
import org.flywaydb.core.api.logging.Log; | ||
import org.flywaydb.core.api.logging.LogCreator; | ||
import org.flywaydb.core.api.logging.LogFactory; | ||
import org.jpos.ee.DB; | ||
|
||
import java.util.Arrays; | ||
import java.util.Properties; | ||
|
||
public class FlywaySupport implements LogCreator, Log { | ||
protected Flyway getFlyway(String configModifier, String args[]) { | ||
LogFactory.setFallbackLogCreator(this); | ||
Properties p = new DB(configModifier).getProperties(); | ||
FluentConfiguration config = Flyway.configure().dataSource( | ||
p.getProperty("hibernate.connection.url"), | ||
p.getProperty("hibernate.connection.username"), | ||
p.getProperty("hibernate.connection.password")) | ||
.outOfOrder(has(args, "--out-of-order")); | ||
return config.load(); | ||
} | ||
|
||
public Log createLogger(Class<?> clazz) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean isDebugEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void debug(String message) { | ||
System.out.println("DEBUG: " + message); | ||
} | ||
|
||
@Override | ||
public void info(String message) { | ||
System.out.println(message); | ||
} | ||
|
||
@Override | ||
public void warn(String message) { | ||
System.err.println("WARNING: " + message); | ||
} | ||
|
||
@Override | ||
public void error(String message) { | ||
System.err.println("ERROR: " + message); | ||
} | ||
|
||
@Override | ||
public void error(String message, Exception e) { | ||
System.err.println("ERROR: " + message); | ||
e.printStackTrace(System.err); | ||
} | ||
|
||
private boolean has (String[] args, String arg) { | ||
return Arrays.stream(args).anyMatch(s -> s.equals(arg)); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
modules/db-flyway/src/main/java/org/jpos/q2/cli/FLYWAY.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2019 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.q2.cli; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.jpos.ee.DB; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.CLISubSystem; | ||
|
||
import java.util.Properties; | ||
|
||
public class FLYWAY implements CLISubSystem { | ||
public static final String PREFIX = "flyway.dbmodifier"; | ||
|
||
@Override | ||
public String getPrompt(CLIContext ctx, String[] args) { | ||
String prefix = null; | ||
if (args.length > 1) { | ||
prefix = args[1]; | ||
ctx.getUserData().put(PREFIX, prefix); | ||
} else { | ||
ctx.getUserData().remove(PREFIX); | ||
} | ||
return "flyway" + (prefix != null ? "[" + args[1] + "]" : "") + "> "; | ||
} | ||
|
||
@Override | ||
public String[] getCompletionPrefixes(CLIContext ctx, String[] args) { | ||
return new String[] { "org.jpos.q2.cli.flyway." }; | ||
} | ||
|
||
private Flyway getFlyWay() { | ||
Properties p = new DB().getProperties(); | ||
return Flyway.configure().dataSource( | ||
p.getProperty("hibernate.connection.url"), | ||
p.getProperty("hibernate.connection.username"), | ||
p.getProperty("hibernate.connection.password")).load(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/db-flyway/src/main/java/org/jpos/q2/cli/flyway/BASELINE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jpos.q2.cli.flyway; | ||
|
||
import org.jpos.flyway.FlywaySupport; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.cli.FLYWAY; | ||
|
||
public class BASELINE extends FlywaySupport implements CLICommand{ | ||
@Override | ||
public void exec(CLIContext cli, String[] args) { | ||
getFlyway((String) cli.getUserData().get(FLYWAY.PREFIX), args).baseline(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
modules/db-flyway/src/main/java/org/jpos/q2/cli/flyway/CLEAN.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jpos.q2.cli.flyway; | ||
|
||
import org.jpos.flyway.FlywaySupport; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.cli.FLYWAY; | ||
|
||
public class CLEAN extends FlywaySupport implements CLICommand{ | ||
@Override | ||
public void exec(CLIContext cli, String[] args) { | ||
boolean superSure = false; | ||
boolean sure = cli.confirm("Are you sure you want to Clean your database (Yes/No) ? "); | ||
if (sure) | ||
superSure = cli.confirm("This action can not be reversed - still want to proceed (Yes/No) ? "); | ||
|
||
if (superSure) | ||
getFlyway((String) cli.getUserData().get(FLYWAY.PREFIX), args).clean(); | ||
else { | ||
cli.println ("No action taken"); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
modules/db-flyway/src/main/java/org/jpos/q2/cli/flyway/INFO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.jpos.q2.cli.flyway; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.MigrationInfo; | ||
import org.flywaydb.core.api.MigrationInfoService; | ||
import org.flywaydb.core.api.MigrationVersion; | ||
import org.flywaydb.core.internal.info.MigrationInfoDumper; | ||
import org.jpos.flyway.FlywaySupport; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.cli.FLYWAY; | ||
|
||
public class INFO extends FlywaySupport implements CLICommand{ | ||
@Override | ||
public void exec(CLIContext cli, String[] args) throws Exception { | ||
Flyway flyway = getFlyway((String) cli.getUserData().get(FLYWAY.PREFIX), args); | ||
MigrationInfoService info = flyway.info(); | ||
MigrationInfo current = info.current(); | ||
MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion(); | ||
MigrationVersion schemaVersionToOutput = currentSchemaVersion == null ? MigrationVersion.EMPTY : currentSchemaVersion; | ||
|
||
cli.println ("Schema version: " + schemaVersionToOutput); | ||
cli.println (""); | ||
cli.println(MigrationInfoDumper.dumpToAsciiTable(info.all())); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/db-flyway/src/main/java/org/jpos/q2/cli/flyway/MIGRATE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jpos.q2.cli.flyway; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.jpos.flyway.FlywaySupport; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.cli.FLYWAY; | ||
|
||
public class MIGRATE extends FlywaySupport implements CLICommand{ | ||
@Override | ||
public void exec(CLIContext cli, String[] args) { | ||
Flyway flyway = getFlyway((String) cli.getUserData().get(FLYWAY.PREFIX), args); | ||
flyway.migrate(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/db-flyway/src/main/java/org/jpos/q2/cli/flyway/REPAIR.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jpos.q2.cli.flyway; | ||
|
||
import org.jpos.flyway.FlywaySupport; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.cli.FLYWAY; | ||
|
||
public class REPAIR extends FlywaySupport implements CLICommand{ | ||
@Override | ||
public void exec(CLIContext cli, String[] args) { | ||
getFlyway((String) cli.getUserData().get(FLYWAY.PREFIX), args).repair(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/db-flyway/src/main/java/org/jpos/q2/cli/flyway/VALIDATE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jpos.q2.cli.flyway; | ||
|
||
import org.jpos.flyway.FlywaySupport; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.q2.cli.FLYWAY; | ||
|
||
public class VALIDATE extends FlywaySupport implements CLICommand{ | ||
@Override | ||
public void exec(CLIContext cli, String[] args) { | ||
getFlyway((String) cli.getUserData().get(FLYWAY.PREFIX), args).validate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters