mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
Provide API to run ddl and migration manually (e.g. with offline DB)
This commit is contained in:
1 parent
68b7deba9d
commit
eb6aacce4b
7 files changed
+249
-44
No files matched your search
@@ -8,8 +8,14 @@ public interface SpiDdlGenerator {
|
||||
/**
|
||||
* Generate and run the DDL for drop-all and create-all scripts.
|
||||
* <p>
|
||||
* Run based on on property settings for ebean.ddl.generate and ebean.ddl.run etc.
|
||||
* Run based on on property settings for ebean.ddl.generate
|
||||
*/
|
||||
void execute(boolean online);
|
||||
void generateDdl();
|
||||
|
||||
/**
|
||||
* Runs the created DDL files.
|
||||
* <p>
|
||||
* Run based on on property settings for ebean.ddl.run etc.
|
||||
*/
|
||||
void runDdl();
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
*/
|
||||
public void executePlugins(boolean online) {
|
||||
if (!config.isDocStoreOnly()) {
|
||||
ddlGenerator.execute(online);
|
||||
ddlGenerator.generateDdl();
|
||||
}
|
||||
for (Plugin plugin : serverPlugins) {
|
||||
plugin.online(online);
|
||||
@@ -359,27 +359,54 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
serverCacheManager.enabledRegions(config.getEnabledL2Regions());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start any services after registering with the ClusterManager.
|
||||
*/
|
||||
public void start() {
|
||||
if (config.isRunMigration() && TenantMode.DB != config.getTenantMode()) {
|
||||
final AutoMigrationRunner migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
|
||||
if (migrationRunner == null) {
|
||||
throw new IllegalStateException("No AutoMigrationRunner found. Probably ebean-migration is not in the classpath?");
|
||||
|
||||
// check, if DB is available to run DDL and migration
|
||||
boolean dbAvailable = !config.isDocStoreOnly()
|
||||
&& !config.isDbOffline()
|
||||
&& config.getDataSource() != null
|
||||
&& config.getTenantMode().isDdlEnabled();
|
||||
|
||||
if (dbAvailable) {
|
||||
if (config.isDdlRun()) {
|
||||
runDdl();
|
||||
}
|
||||
final String dbSchema = config.getDbSchema();
|
||||
if (dbSchema != null) {
|
||||
migrationRunner.setDefaultDbSchema(dbSchema);
|
||||
if (config.isRunMigration()) {
|
||||
runMigration();
|
||||
}
|
||||
migrationRunner.setName(config.getName());
|
||||
migrationRunner.setPlatform(config.getDatabasePlatform().getPlatform().base().name().toLowerCase());
|
||||
migrationRunner.loadProperties(config.getProperties());
|
||||
migrationRunner.run(config.getDataSource());
|
||||
} else if (config.isDdlRun() || config.isRunMigration()) {
|
||||
log.warn("There was a request to run DDL or migration, but this is currently not possible, as the database is not available");
|
||||
}
|
||||
startQueryPlanCapture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDdl() {
|
||||
ddlGenerator.runDdl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runMigration() {
|
||||
final AutoMigrationRunner migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
|
||||
if (migrationRunner == null) {
|
||||
throw new IllegalStateException(
|
||||
"No AutoMigrationRunner found. Probably ebean-migration is not in the classpath?");
|
||||
}
|
||||
|
||||
final String dbSchema = config.getDbSchema();
|
||||
if (dbSchema != null) {
|
||||
migrationRunner.setDefaultDbSchema(dbSchema);
|
||||
}
|
||||
migrationRunner.setName(config.getName());
|
||||
migrationRunner.setPlatform(config.getDatabasePlatform().getPlatform().base().name().toLowerCase());
|
||||
migrationRunner.loadProperties(config.getProperties());
|
||||
migrationRunner.run(dataSource());
|
||||
}
|
||||
|
||||
private void startQueryPlanCapture() {
|
||||
if (config.isQueryPlanCapture()) {
|
||||
long secs = config.getQueryPlanCapturePeriodSecs();
|
||||
|
||||
@@ -610,8 +610,13 @@ public final class InternalConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(boolean online) {
|
||||
if (online && ddlRun) {
|
||||
public void generateDdl() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDdl() {
|
||||
if (ddlRun) {
|
||||
CoreLog.log.error("Configured to run DDL but ebean-ddl-generator is not in the classpath (or ebean-test in the test classpath?)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user