ENH: allow server startup without running ddl and thus allowing starting with the database not yet up and later lazily initializing the database and running ddl

This commit is contained in:
Jonas Pöhler committed 2021-10-22 13:59:54 +02:00
1 parent 45aa04e086
commit af0f9a4d15
7 files changed
+233 -4

No files matched your search

@@ -56,6 +56,10 @@ public class DatabasePlatformFactory {
if (config.getDataSourceConfig().isOffline()) {
throw new PersistenceException("DatabasePlatformName must be specified with offline mode");
}
if (config.getTenantMode().isDynamicDataSource()) {
throw new IllegalStateException("DatabasePlatform must be explicitly set on ServerConfig for TenantMode "
+ config.getTenantMode());
}
// guess using meta data from driver
return byDataSource(config.getDataSource());
@@ -177,6 +177,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
private final long slowQueryMicros;
private final SlowQueryListener slowQueryListener;
private final boolean disableL2Cache;
private final boolean initDatabase;
private boolean shutdown;
/**
@@ -224,6 +225,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
this.serverPlugins = config.getPlugins();
this.ddlGenerator = config.initDdlGenerator(this);
this.scriptRunner = new DScriptRunner(this);
this.initDatabase = !config.getConfig().skipInitDatabase();
configureServerPlugins();
// Register with the JVM Shutdown hook
@@ -248,13 +250,21 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
@Override
public void initDatabase(boolean online) {
if (!config.isDocStoreOnly()) {
ddlGenerator.execute(online);
}
}
/**
* Execute all the plugins with an online flag indicating the DB is up or not.
*/
public void executePlugins(boolean online) {
if (!config.isDocStoreOnly()) {
ddlGenerator.execute(online);
if (initDatabase) {
initDatabase(online);
}
for (Plugin plugin : serverPlugins) {
plugin.online(online);
}