Skip to content

Commit

Permalink
[playframework#913] Evolution state is now only checked in dev mode o…
Browse files Browse the repository at this point in the history
…n every request

It can also be disabled in application.conf
  • Loading branch information
Florian Gutmann authored and mbknor committed Jun 17, 2011
1 parent c1b3f18 commit a06299a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion documentation/manual/evolutions.textile
Expand Up @@ -40,6 +40,9 @@ DROP TABLE User;

As you see you have to delimitate the both *Ups* and *Downs* section by using comments in your SQL script.

Evolutions are automatically activated if a database is configured in application.conf and evolution scripts are present. You can disable them by setting **evolutions.enabled=false** in application.conf.
For example when tests set up their own database you can disable evolutions for the test environment.

When **evolutions** are activated, Play will check your database schema state before each request in DEV mode, or before starting the application in PROD mode. In DEV mode, if your database schema is not up to date, an error page will suggest that you synchronise your database schema by running the appropriate SQL script.

!images/evolutions!
Expand Down Expand Up @@ -295,4 +298,4 @@ bc. $ play evolutions:resolve

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

Learn how to configure %(next)"Logging":logs%.
Learn how to configure %(next)"Logging":logs%.
14 changes: 12 additions & 2 deletions framework/src/play/db/Evolutions.java
Expand Up @@ -34,6 +34,11 @@
*/
public class Evolutions extends PlayPlugin {

/**
* Indicates if evolutions is disabled in application.conf ("evolutions.enabled" property)
*/
private boolean disabled = false;

protected static ComboPooledDataSource getDatasource() {
DBConfig dbConfig = DB.getDBConfig(DBConfig.defaultDbConfigName, true);
if (dbConfig==null) {
Expand Down Expand Up @@ -194,6 +199,9 @@ public boolean rawInvocation(Request request, Response response) throws Exceptio

@Override
public void beforeInvocation() {
if(disabled || Play.mode.isProd()) {
return;
}
try {
checkEvolutionsState();
} catch (InvalidDatabaseRevision e) {
Expand All @@ -208,7 +216,9 @@ public void beforeInvocation() {

@Override
public void onApplicationStart() {
if (Play.mode.isProd()) {
disabled = "false".equals(Play.configuration.getProperty("evolutions.enabled", "true"));

if (! disabled && Play.mode.isProd()) {
try {
checkEvolutionsState();
} catch (InvalidDatabaseRevision e) {
Expand All @@ -219,7 +229,7 @@ public void onApplicationStart() {
}
}
}

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 a06299a

Please sign in to comment.