diff --git a/build.sbt b/build.sbt index 0e682953..e54ae63c 100644 --- a/build.sbt +++ b/build.sbt @@ -23,6 +23,7 @@ val previousVersion: Option[String] = Some("8.0.0") lazy val mimaSettings = Seq( mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet, mimaBinaryIssueFilters ++= Seq( + ProblemFilters.exclude[ReversedMissingMethodProblem]("play.db.ebean.EbeanConfig.generateEvolutionsScripts"), ) ) diff --git a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java index 8e91d061..e7fe4349 100644 --- a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java @@ -26,11 +26,22 @@ public class DefaultEbeanConfig implements EbeanConfig { private final String defaultServer; + private final Map serverConfigs; - public DefaultEbeanConfig(String defaultServer, Map serverConfigs) { + private final boolean generateEvolutionsScripts; + + public DefaultEbeanConfig( + String defaultServer, + Map serverConfigs, + boolean generateEvolutionsScripts) { this.defaultServer = defaultServer; this.serverConfigs = serverConfigs; + this.generateEvolutionsScripts = generateEvolutionsScripts; + } + + public DefaultEbeanConfig(String defaultServer, Map serverConfigs) { + this(defaultServer, serverConfigs, true); } @Override @@ -43,11 +54,18 @@ public Map serverConfigs() { return serverConfigs; } + @Override + public boolean generateEvolutionsScripts() { + return generateEvolutionsScripts; + } + @Singleton public static class EbeanConfigParser implements Provider { private final Config config; + private final Environment environment; + private final DBApi dbApi; private static final Logger.ALogger LOGGER = Logger.of(DefaultEbeanConfig.class); @@ -100,7 +118,10 @@ public EbeanConfig parse() { serverConfigs.put(key, serverConfig); } - return new DefaultEbeanConfig(ebeanConfig.getDefaultDatasource(), serverConfigs); + return new DefaultEbeanConfig( + ebeanConfig.getDefaultDatasource(), + serverConfigs, + ebeanConfig.generateEvolutionsScripts()); } private void setServerConfigDataSource(String key, DatabaseConfig serverConfig) { diff --git a/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java b/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java index f8dd80b7..f2a2b4f2 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java @@ -12,4 +12,6 @@ public interface EbeanConfig { String defaultServer(); Map serverConfigs(); + + boolean generateEvolutionsScripts(); } diff --git a/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java b/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java index d0e34c6c..dcb47ccb 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java @@ -64,6 +64,9 @@ public void create() { if (environment.isProd()) { return; } + if (!config.generateEvolutionsScripts()) { + return; + } config .serverConfigs() .forEach( diff --git a/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java b/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java index 39e8d417..941e7bf0 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java @@ -18,11 +18,22 @@ public class EbeanParsedConfig { private final String defaultDatasource; + private final Map> datasourceModels; - public EbeanParsedConfig(String defaultDatasource, Map> datasourceModels) { + private final boolean generateEvolutionsScripts; + + public EbeanParsedConfig( + String defaultDatasource, + Map> datasourceModels, + boolean generateEvolutionsScripts) { this.defaultDatasource = defaultDatasource; this.datasourceModels = datasourceModels; + this.generateEvolutionsScripts = generateEvolutionsScripts; + } + + public EbeanParsedConfig(String defaultDatasource, Map> datasourceModels) { + this(defaultDatasource, datasourceModels, true); } public String getDefaultDatasource() { @@ -33,6 +44,10 @@ public Map> getDatasourceModels() { return datasourceModels; } + public boolean generateEvolutionsScripts() { + return generateEvolutionsScripts; + } + /** * Parse a play configuration. * @@ -44,6 +59,7 @@ public static EbeanParsedConfig parseFromConfig(Config config) { Config playEbeanConfig = config.getConfig("play.ebean"); String defaultDatasource = playEbeanConfig.getString("defaultDatasource"); String ebeanConfigKey = playEbeanConfig.getString("config"); + boolean generateEvolutionsScripts = playEbeanConfig.getBoolean("generateEvolutionsScripts"); Map> datasourceModels = new HashMap<>(); @@ -64,6 +80,6 @@ public static EbeanParsedConfig parseFromConfig(Config config) { datasourceModels.put(key, models); }); } - return new EbeanParsedConfig(defaultDatasource, datasourceModels); + return new EbeanParsedConfig(defaultDatasource, datasourceModels, generateEvolutionsScripts); } } diff --git a/play-ebean/src/main/resources/reference.conf b/play-ebean/src/main/resources/reference.conf index 530ad5aa..dfce38b9 100644 --- a/play-ebean/src/main/resources/reference.conf +++ b/play-ebean/src/main/resources/reference.conf @@ -9,5 +9,8 @@ play { # The name of the default ebean datasource defaultDatasource = "default" + + # The key to control the generation of the Evolutions scripts + generateEvolutionsScripts = true } } diff --git a/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java b/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java index 11f8c4c3..fd899695 100644 --- a/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java +++ b/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java @@ -26,6 +26,7 @@ public void defaultConfig() { EbeanParsedConfig config = parse(Collections.emptyMap()); assertThat(config.getDefaultDatasource(), equalTo("default")); assertThat(config.getDatasourceModels().size(), equalTo(0)); + assertThat(config.generateEvolutionsScripts(), equalTo(Boolean.TRUE)); } @Test @@ -52,6 +53,13 @@ public void customDefault() { assertThat(config.getDefaultDatasource(), equalTo("custom")); } + @Test + public void disableGenerateEvolutionsScripts() { + EbeanParsedConfig config = + parse(ImmutableMap.of("play.ebean.generateEvolutionsScripts", false)); + assertThat(config.generateEvolutionsScripts(), equalTo(Boolean.FALSE)); + } + @Test public void customConfig() { EbeanParsedConfig config =