Skip to content

Commit

Permalink
[#1736] Allow to disable modules evolutions or from a specfic module
Browse files Browse the repository at this point in the history
  • Loading branch information
xael-fry authored and Notalifeform committed Oct 25, 2013
1 parent e29b233 commit c4d8a33
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
17 changes: 17 additions & 0 deletions documentation/manual/configuration.textile
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,23 @@ bc. evolutions.enabled=false
Default: @true@


h3(#modules.evolutions.enabled). modules.evolutions.enabled

Used to disable "database evolutions":evolutions from all modules

bc. modules.evolutions.enabled=false

Default: @true@

h3(#[module name].evolutions.enabled). [module name].evolutions.enabled

Used to disable "database evolutions":evolutions from a given module

bc. [module name].evolutions.enabled=false

Default: @true@


h2(#test). Test runner

h3(#headlessBrowser). headlessBrowser
Expand Down
13 changes: 13 additions & 0 deletions documentation/manual/evolutions.textile
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@ bc. $play evolutions:apply -Dmodules=module3

p(note). If you use the command-line switch, your application will **NOT** be included by default, unless you specify it in the list of modules.

If you wish to only work with the application's evolutions, you can use the @modules.evolutions.enabled@ parameters to configure the evolutions from all modules

bc. modules.evolutions.enabled=false

Default: @true@

If you wish to disable evolutions from a specific module, you can use the @[module name].evolutions.enabled@ parameters to configure the evolutions from the given module

bc. [module name].evolutions.enabled=false

Default: @true@


p(note). **Continuing the discussion**

Learn how to configure %(next)"Logging":logs%.
34 changes: 28 additions & 6 deletions framework/src/play/db/Evolutions.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ private static void populateModulesWithSpecificModules() {
if (Play.modules.containsKey(specificModule)) {
VirtualFile moduleRoot = Play.modules.get(specificModule);

if(moduleRoot.child("db/evolutions").exists()) {
if(!isModuleEvolutionDisabled(specificModule) && moduleRoot.child("db/evolutions").exists()) {
modulesWithEvolutions.put(specificModule, moduleRoot.child("db/evolutions"));
} else {
System.out.println("~ '" + specificModule + "' module doesn't have any evolutions scripts in it.");
System.out.println("~ '" + specificModule + "' module doesn't have any evolutions scripts in it or evolutions are disabled.");
System.out.println("~");
System.exit(-1);
}
Expand All @@ -231,11 +231,18 @@ private static void populateModulesWithSpecificModules() {

private static void populateModulesWithEvolutions() {
/** Check that evolutions are enabled **/

for(Entry<String, VirtualFile> moduleRoot : Play.modules.entrySet()) {
if(moduleRoot.getValue().child("db/evolutions").exists()) {
modulesWithEvolutions.put(moduleRoot.getKey(), moduleRoot.getValue().child("db/evolutions"));
if(!isModuleEvolutionDisabled()){
for(Entry<String, VirtualFile> moduleRoot : Play.modules.entrySet()) {
if(moduleRoot.getValue().child("db/evolutions").exists()) {
if(!isModuleEvolutionDisabled(moduleRoot.getKey())){
modulesWithEvolutions.put(moduleRoot.getKey(), moduleRoot.getValue().child("db/evolutions"));
} else {
System.out.println("~ '" + moduleRoot.getKey() + "' module evolutions are disabled.");
}
}
}
}else{
System.out.println("~ Module evolutions are disabled.");
}

addMainProjectToModuleList();
Expand Down Expand Up @@ -313,6 +320,21 @@ public void onApplicationStart() {
}
}

/**
* Checks if evolutions is disabled in application.conf (property "evolutions.enabled")
*/
private boolean isDisabled() {
return "false".equals(Play.configuration.getProperty("evolutions.enabled", "true"));
}

private static boolean isModuleEvolutionDisabled(){
return "false".equals(Play.configuration.getProperty("modules.evolutions.enabled", "true"));
}

private static boolean isModuleEvolutionDisabled(String name){
return "false".equals(Play.configuration.getProperty(name + ".evolutions.enabled", "true"));
}

public static synchronized void resolve(int revision) {
try {
execute("update play_evolutions set state = 'applied' where state = 'applying_up' and id = " + revision);
Expand Down

0 comments on commit c4d8a33

Please sign in to comment.