Skip to content

Commit

Permalink
PR ebean-orm#3151 - NEW: DDL generation can be invoked separately
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml committed Aug 10, 2023
1 parent d9383dc commit e7f157e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions ebean-api/src/main/java/io/ebean/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -1518,4 +1518,8 @@ default Set<Property> checkUniqueness(Object bean, Transaction transaction) {
*/
void truncate(Class<?>... beanTypes);

/**
* RunDdl manually. This can be used if 'db.ddl.run=false' is set and you plan to run DDL manually.
*/
void runDdl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public interface SpiDdlGenerator {
*/
void execute(boolean online);

/**
* Run DDL manually. This can be used to initialize multi tenant environments or if you plan not to run
* DDL on startup
*/
void runDdl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2291,4 +2291,9 @@ List<MetaQueryPlan> queryPlanInit(QueryPlanInit initRequest) {
List<MetaQueryPlan> queryPlanCollectNow(QueryPlanRequest request) {
return queryPlanManager.collect(request);
}

@Override
public void runDdl() {
ddlGenerator.runDdl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ private static class NoopDdl implements SpiDdlGenerator {
this.ddlRun = ddlRun;
}

@Override
public void runDdl() {
CoreLog.log.log(ERROR, "Manual DDL run not possible");
}

@Override
public void execute(boolean online) {
if (online && ddlRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ public DdlGenerator(SpiEbeanServer server) {
if (!config.getTenantMode().isDdlEnabled() && config.isDdlRun()) {
log.log(WARNING, "DDL can''t be run on startup with TenantMode " + config.getTenantMode());
this.runDdl = false;
this.useMigrationStoredProcedures = false;
} else {
this.runDdl = config.isDdlRun();
this.useMigrationStoredProcedures = config.getDatabasePlatform().useMigrationStoredProcedures();
}
this.useMigrationStoredProcedures = config.getDatabasePlatform() != null && config.getDatabasePlatform().useMigrationStoredProcedures();
this.scriptTransform = createScriptTransform(config);
this.baseDir = initBaseDir();
}
Expand All @@ -85,7 +84,7 @@ private File initBaseDir() {
@Override
public void execute(boolean online) {
generateDdl();
if (online) {
if (online && runDdl) {
runDdl();
}
}
Expand All @@ -105,16 +104,15 @@ protected void generateDdl() {
/**
* Run the DDL drop and DDL create scripts if properties have been set.
*/
protected void runDdl() {
if (runDdl) {
Connection connection = null;
try {
connection = obtainConnection();
runDdlWith(connection);
} finally {
JdbcClose.rollback(connection);
JdbcClose.close(connection);
}
@Override
public void runDdl() {
Connection connection = null;
try {
connection = obtainConnection();
runDdlWith(connection);
} finally {
JdbcClose.rollback(connection);
JdbcClose.close(connection);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,9 @@ public void loadBeanL2(EntityBeanIntercept ebi) {
public void loadBean(EntityBeanIntercept ebi) {

}

@Override
public void runDdl() {

}
}

0 comments on commit e7f157e

Please sign in to comment.