Skip to content

Commit

Permalink
[playframework#1383] ♻ Support disabled evolutions for command line o…
Browse files Browse the repository at this point in the history
…perations
  • Loading branch information
holajsh committed Mar 25, 2022
1 parent eb22b0b commit 6eb5738
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions framework/src/play/db/Evolutions.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,64 +79,67 @@ public static void main(String[] args) throws SQLException {
System.out.println("~ Connected to " + DB.getDataSource(dbName).getConnection().getMetaData().getURL());

for (Entry<String, VirtualFile> moduleRoot : modulesWithEvolutions.entrySet()) {

/** Summary **/
Evolution database = listDatabaseEvolutions(dbName, moduleRoot.getKey()).peek();
Evolution application = listApplicationEvolutions(dbName, moduleRoot.getKey(), moduleRoot.getValue()).peek();

boolean needToCheck = true;
if ("resolve".equals(System.getProperty("mode"))) {
needToCheck = handleResolveAction(dbName, moduleRoot);
}
if (needToCheck) {
/** Check inconsistency **/
try {
checkEvolutionsState(dbName);
} catch (InconsistentDatabase e) {
defaultExitCode = false;
System.out.println("~");
System.out.println("~ Your database " + dbName + " is in an inconsistent state!");
System.out.println("~");
System.out.println("~ While applying this script part:");
System.out.println("");
System.out.println(e.getEvolutionScript());
System.out.println("");
System.out.println("~ The following error occurred:");
System.out.println("");
System.out.println(e.getError());
System.out.println("");
System.out.println("~ Please correct it manually, and mark it resolved by running `play evolutions:resolve`");
System.out.println("~");
continue;
} catch (InvalidDatabaseRevision e) {
// see later
if (!isDatabaseEvolutionDisabled(dbName)) {
/** Summary **/
Evolution database = listDatabaseEvolutions(dbName, moduleRoot.getKey()).peek();
Evolution application = listApplicationEvolutions(dbName, moduleRoot.getKey(), moduleRoot.getValue()).peek();

boolean needToCheck = true;
if ("resolve".equals(System.getProperty("mode"))) {
needToCheck = handleResolveAction(dbName, moduleRoot);
}
if (needToCheck) {
/** Check inconsistency **/
try {
checkEvolutionsState(dbName);
} catch (InconsistentDatabase e) {
defaultExitCode = false;
System.out.println("~");
System.out.println("~ Your database " + dbName + " is in an inconsistent state!");
System.out.println("~");
System.out.println("~ While applying this script part:");
System.out.println("");
System.out.println(e.getEvolutionScript());
System.out.println("");
System.out.println("~ The following error occurred:");
System.out.println("");
System.out.println(e.getError());
System.out.println("");
System.out.println("~ Please correct it manually, and mark it resolved by running `play evolutions:resolve`");
System.out.println("~");
continue;
} catch (InvalidDatabaseRevision e) {
// see later
}

System.out.print("~ '" + moduleRoot.getKey() + "' Application revision is " + application.revision + " ["
+ application.hash.substring(0, 7) + "]");
System.out.println(" and '" + moduleRoot.getKey() + "' Database revision is " + database.revision + " ["
+ database.hash.substring(0, 7) + "]");
System.out.println("~");

/** Evolution script **/
List<Evolution> evolutions = getEvolutionScript(dbName, moduleRoot.getKey(), moduleRoot.getValue());
if (evolutions.isEmpty()) {
System.out.println("~ Your database " + dbName + " is up to date for " + moduleRoot.getKey());
System.out.print("~ '" + moduleRoot.getKey() + "' Application revision is " + application.revision + " ["
+ application.hash.substring(0, 7) + "]");
System.out.println(" and '" + moduleRoot.getKey() + "' Database revision is " + database.revision + " ["
+ database.hash.substring(0, 7) + "]");
System.out.println("~");
} else {
if ("apply".equals(System.getProperty("mode"))) {
if (!handleApplyAction(dbName, moduleRoot, evolutions)) {
defaultExitCode = false;
}
} else if ("markApplied".equals(System.getProperty("mode"))) {
if (!handleMarkAppliedAction(dbName, moduleRoot, evolutions)) {

/** Evolution script **/
List<Evolution> evolutions = getEvolutionScript(dbName, moduleRoot.getKey(), moduleRoot.getValue());
if (evolutions.isEmpty()) {
System.out.println("~ Your database " + dbName + " is up to date for " + moduleRoot.getKey());
System.out.println("~");
} else {
if ("apply".equals(System.getProperty("mode"))) {
if (!handleApplyAction(dbName, moduleRoot, evolutions)) {
defaultExitCode = false;
}
} else if ("markApplied".equals(System.getProperty("mode"))) {
if (!handleMarkAppliedAction(dbName, moduleRoot, evolutions)) {
defaultExitCode = false;
}
} else {
defaultExitCode = false;
handleDefaultAction(dbName, moduleRoot, evolutions);
}
} else {
defaultExitCode = false;
handleDefaultAction(dbName, moduleRoot, evolutions);
}
}
} else {
System.out.println("~ Database evolutions are disabled for " + dbName + ". Skipping check.");
}
}
}
Expand Down

0 comments on commit 6eb5738

Please sign in to comment.