Skip to content

Commit ac93b58

Browse files
committed
DDL generation can be invoked separately
1 parent 6d5f740 commit ac93b58

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

ebean-api/src/main/java/io/ebean/Database.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,4 +1520,8 @@ static DatabaseBuilder builder() {
15201520
*/
15211521
void truncate(Class<?>... beanTypes);
15221522

1523+
/**
1524+
* RunDdl manually. This can be used if 'db.ddl.run=false' is set and you plan to run DDL manually.
1525+
*/
1526+
void runDdl();
15231527
}

ebean-core/src/main/java/io/ebeaninternal/api/SpiDdlGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ public interface SpiDdlGenerator {
1212
*/
1313
void execute(boolean online);
1414

15+
/**
16+
* Run DDL manually. This can be used to initialize multi tenant environments or if you plan not to run
17+
* DDL on startup
18+
*/
19+
void runDdl();
1520
}

ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,4 +2285,9 @@ List<MetaQueryPlan> queryPlanInit(QueryPlanInit initRequest) {
22852285
List<MetaQueryPlan> queryPlanCollectNow(QueryPlanRequest request) {
22862286
return queryPlanManager.collect(request);
22872287
}
2288+
2289+
@Override
2290+
public void runDdl() {
2291+
ddlGenerator.runDdl();
2292+
}
22882293
}

ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ private static class NoopDdl implements SpiDdlGenerator {
619619
this.ddlRun = ddlRun;
620620
}
621621

622+
@Override
623+
public void runDdl() {
624+
CoreLog.log.log(ERROR, "Manual DDL run not possible");
625+
}
626+
622627
@Override
623628
public void execute(boolean online) {
624629
if (online && ddlRun) {

ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ public DdlGenerator(SpiEbeanServer server) {
6363
if (!config.getTenantMode().isDdlEnabled() && config.isDdlRun()) {
6464
log.log(WARNING, "DDL can''t be run on startup with TenantMode " + config.getTenantMode());
6565
this.runDdl = false;
66-
this.useMigrationStoredProcedures = false;
6766
} else {
6867
this.runDdl = config.isDdlRun();
69-
this.useMigrationStoredProcedures = config.getDatabasePlatform().useMigrationStoredProcedures();
7068
}
69+
this.useMigrationStoredProcedures = config.getDatabasePlatform() != null && config.getDatabasePlatform().useMigrationStoredProcedures();
7170
this.scriptTransform = createScriptTransform(config);
7271
this.baseDir = initBaseDir();
7372
}
@@ -85,7 +84,7 @@ private File initBaseDir() {
8584
@Override
8685
public void execute(boolean online) {
8786
generateDdl();
88-
if (online) {
87+
if (online && runDdl) {
8988
runDdl();
9089
}
9190
}
@@ -105,16 +104,15 @@ protected void generateDdl() {
105104
/**
106105
* Run the DDL drop and DDL create scripts if properties have been set.
107106
*/
108-
protected void runDdl() {
109-
if (runDdl) {
110-
Connection connection = null;
111-
try {
112-
connection = obtainConnection();
113-
runDdlWith(connection);
114-
} finally {
115-
JdbcClose.rollback(connection);
116-
JdbcClose.close(connection);
117-
}
107+
@Override
108+
public void runDdl() {
109+
Connection connection = null;
110+
try {
111+
connection = obtainConnection();
112+
runDdlWith(connection);
113+
} finally {
114+
JdbcClose.rollback(connection);
115+
JdbcClose.close(connection);
118116
}
119117
}
120118

ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,9 @@ public void loadBeanL2(EntityBeanIntercept ebi) {
632632
public void loadBean(EntityBeanIntercept ebi) {
633633

634634
}
635+
636+
@Override
637+
public void runDdl() {
638+
639+
}
635640
}

0 commit comments

Comments
 (0)