public static synchronized void checkEvolutionsState() { // Look over all the DB Set<String> dBNames = Configuration.getDbNames(); for (String dbName : dBNames) { checkEvolutionsState(dbName); } }
/** * Method to handle the "resolve" action * * @param dbName * database name * @param moduleRoot * the module root of evolutions * @return true if need to check, false otherwise */ private static boolean handleResolveAction(String dbName, Entry<String, VirtualFile> moduleRoot) { try { checkEvolutionsState(dbName); System.out.println("~"); System.out.println("~ Nothing to resolve for " + moduleRoot.getKey() + "..."); System.out.println("~"); return false; } catch (InconsistentDatabase e) { resolve(dbName, moduleRoot.getKey(), e.getRevision()); System.out.println("~"); System.out.println("~ Revision " + e.getRevision() + " for " + moduleRoot.getKey() + " has been resolved;"); System.out.println("~"); } catch (InvalidDatabaseRevision e) { // see later } return true; }
@Override public void beforeInvocation() { if (isDisabled() || Play.mode.isProd()) { return; } try { checkEvolutionsState(); } catch (InvalidDatabaseRevision e) { Set<String> dbNames = Configuration.getDbNames(); for (String dbName : dbNames) { Configuration dbConfig = new Configuration(dbName); for (Entry<String, VirtualFile> moduleRoot : modulesWithEvolutions.entrySet()) { if ("mem".equals(dbConfig.getProperty("db")) && listDatabaseEvolutions(e.getDbName(), moduleRoot.getKey()).peek().revision == 0) { Logger.info("Automatically applying evolutions in in-memory database"); Logger.info("Applying evolutions for '" + moduleRoot.getKey() + "'"); applyScript(true, moduleRoot.getKey(), moduleRoot.getValue()); } else { throw e; } } } } }
checkEvolutionsState(dbName); } catch (InconsistentDatabase e) { defaultExitCode = false;
@Override public void onApplicationStart() { if (!isDisabled()) { populateModulesWithEvolutions(); if (Play.mode.isProd()) { try { checkEvolutionsState(); } catch (InvalidDatabaseRevision e) { Logger.warn(""); Logger.warn("Your database is not up to date."); Logger.warn("Use `play evolutions` command to manage database evolutions."); throw e; } } } }