#514 - ENH: Add ebean.ddl.createOnly=true ... such that all the drop table statements are skipped (for running tests against H2 usually)

This commit is contained in:
Robin Bygrave
2016-01-07 10:06:35 +13:00
parent f6dc294bc2
commit e5d8804591
2 changed files with 39 additions and 4 deletions
@@ -212,6 +212,8 @@ public class ServerConfig {
private boolean ddlRun;
private boolean ddlCreateOnly;
private boolean useJtaTransactionManager;
/**
@@ -1529,19 +1531,45 @@ public class ServerConfig {
}
/**
* Set to true to run the DDL generation on startup.
* Set to true to generate the "create all" DDL on startup.
*
* Typically we want this on when we are running tests locally (and often using H2)
* and we want to create the full DB schema from scratch to run tests.
*/
public void setDdlGenerate(boolean ddlGenerate) {
this.ddlGenerate = ddlGenerate;
}
/**
* Set to true to run the generated DDL on startup.
* Set to true to run the generated "create all DDL" on startup.
*
* Typically we want this on when we are running tests locally (and often using H2)
* and we want to create the full DB schema from scratch to run tests.
*/
public void setDdlRun(boolean ddlRun) {
this.ddlRun = ddlRun;
}
/**
* Return true if the "drop all ddl" should be skipped.
*
* Typically we want to do this when using H2 (in memory) as our test database and the drop statements
* are not required so skipping the drop table statements etc makes it faster with less noise in the logs.
*/
public boolean isDdlCreateOnly() {
return ddlCreateOnly;
}
/**
* Set to true if the "drop all ddl" should be skipped.
*
* Typically we want to do this when using H2 (in memory) as our test database and the drop statements
* are not required so skipping the drop table statements etc makes it faster with less noise in the logs.
*/
public void setDdlCreateOnly(boolean ddlCreateOnly) {
this.ddlCreateOnly = ddlCreateOnly;
}
/**
* Return true if the DDL should be generated.
*/
@@ -2232,6 +2260,7 @@ public class ServerConfig {
ddlGenerate = p.getBoolean("ddl.generate", ddlGenerate);
ddlRun = p.getBoolean("ddl.run", ddlRun);
ddlCreateOnly = p.getBoolean("ddl.createOnly", ddlCreateOnly);
classes = getClasses(p);
}
@@ -33,6 +33,7 @@ public class DdlGenerator implements SpiEbeanPlugin {
private boolean generateDdl;
private boolean runDdl;
private boolean createOnly;
private CurrentModel currentModel;
private String dropContent;
@@ -42,6 +43,7 @@ public class DdlGenerator implements SpiEbeanPlugin {
this.server = server;
this.generateDdl = serverConfig.isDdlGenerate();
this.runDdl = serverConfig.isDdlRun();
this.createOnly = serverConfig.isDdlCreateOnly();
}
/**
@@ -60,7 +62,9 @@ public class DdlGenerator implements SpiEbeanPlugin {
*/
public void generateDdl() {
if (generateDdl) {
writeDrop(getDropFileName());
if (!createOnly) {
writeDrop(getDropFileName());
}
writeCreate(getCreateFileName());
}
}
@@ -78,7 +82,9 @@ public class DdlGenerator implements SpiEbeanPlugin {
if (createContent == null) {
createContent = readFile(getCreateFileName());
}
runScript(true, dropContent);
if (!createOnly) {
runScript(true, dropContent);
}
runScript(false, createContent);
} catch (IOException e) {