public static synchronized boolean applyScript(boolean runScript, String moduleKey, VirtualFile evolutionsDirectory) { // Look over all the DB Set<String> dBNames = Configuration.getDbNames(); for (String dbName : dBNames) { return applyScript(dbName, runScript, moduleKey, evolutionsDirectory); } return true; }
/** * Method to handle the "markApplied" action * * @param dbName * database name * @param moduleRoot * the module root of evolutions * @param evolutions * list of evolutions * @return true if action was applied successfully, false otherwise */ private static boolean handleMarkAppliedAction(String dbName, Entry<String, VirtualFile> moduleRoot, List<Evolution> evolutions) { if (applyScript(dbName, false, moduleRoot.getKey(), moduleRoot.getValue())) { System.out.println("~ Evolutions script marked as applied for " + moduleRoot.getKey() + "!"); System.out.println("~"); return true; } else { System.out.println("~ Can't apply evolutions for " + moduleRoot.getKey() + "..."); System.out.println("~"); return false; } }
System.out.println("# ------------------------------------------------------------------------------"); System.out.println(""); if (applyScript(dbName, true, moduleRoot.getKey(), moduleRoot.getValue())) { System.out.println("~"); System.out.println("~ Evolutions script successfully applied for " + moduleRoot.getKey() + "!");
@Override public boolean rawInvocation(Request request, Response response) throws Exception { // Mark an evolution as resolved if (Play.mode.isDev() && request.method.equals("POST") && request.url.matches("^/@evolutions/force/[a-zA-Z0-9]+/[0-9]+$")) { int index = request.url.lastIndexOf("/@evolutions/force/") + "/@evolutions/force/".length(); String dbName = DB.DEFAULT; String moduleKey = request.url.substring(index, request.url.lastIndexOf("/")); int revision = Integer.parseInt(request.url.substring(request.url.lastIndexOf("/") + 1)); resolve(dbName, moduleKey, revision); new Redirect("/").apply(request, response); return true; } // Apply the current evolution script if (Play.mode.isDev() && request.method.equals("POST") && request.url.equals("/@evolutions/apply")) { for (Entry<String, VirtualFile> moduleRoot : modulesWithEvolutions.entrySet()) { applyScript(true, moduleRoot.getKey(), moduleRoot.getValue()); } new Redirect("/").apply(request, response); return true; } return super.rawInvocation(request, response); }
@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; } } } } }