From d810de4f9511f03e98f4e4207ed0be6150402559 Mon Sep 17 00:00:00 2001 From: Vadim Vera Date: Wed, 10 Jan 2024 11:29:11 -0500 Subject: [PATCH 1/4] Introduce configuration parameter to control the generation of the evolution SQL files (cherry picked from commit d2910e31fffddc1e53d445f37b4b627c8b27943a) --- .../java/play/db/ebean/DefaultEbeanConfig.java | 15 ++++++++++++--- .../src/main/java/play/db/ebean/EbeanConfig.java | 1 + .../play/db/ebean/EbeanDynamicEvolutions.java | 3 +++ .../java/play/db/ebean/EbeanParsedConfig.java | 14 +++++++++++--- play-ebean/src/main/resources/reference.conf | 3 +++ .../java/play/db/ebean/EbeanParsedConfigTest.java | 7 +++++++ 6 files changed, 37 insertions(+), 6 deletions(-) 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..d121cfc5 100644 --- a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java @@ -24,15 +24,24 @@ /** Ebean server configuration. */ @Singleton public class DefaultEbeanConfig implements EbeanConfig { + private final Boolean ddlGenerate; private final String defaultServer; + private final Map serverConfigs; - public DefaultEbeanConfig(String defaultServer, Map serverConfigs) { + public DefaultEbeanConfig( + Boolean ddlGenerate, String defaultServer, Map serverConfigs) { + this.ddlGenerate = ddlGenerate; this.defaultServer = defaultServer; this.serverConfigs = serverConfigs; } + @Override + public Boolean ddlGenerate() { + return ddlGenerate; + } + @Override public String defaultServer() { return defaultServer; @@ -70,7 +79,6 @@ public EbeanConfig get() { * @return a config for Ebean servers. */ public EbeanConfig parse() { - EbeanParsedConfig ebeanConfig = EbeanParsedConfig.parseFromConfig(config); Map serverConfigs = new HashMap<>(); @@ -100,7 +108,8 @@ public EbeanConfig parse() { serverConfigs.put(key, serverConfig); } - return new DefaultEbeanConfig(ebeanConfig.getDefaultDatasource(), serverConfigs); + return new DefaultEbeanConfig( + ebeanConfig.getDdlGenerate(), ebeanConfig.getDefaultDatasource(), serverConfigs); } 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..b1d9ec3b 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java @@ -8,6 +8,7 @@ import java.util.Map; public interface EbeanConfig { + Boolean ddlGenerate(); String defaultServer(); 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..7a870725 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.ddlGenerate().equals(Boolean.FALSE)) { + 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..613741ce 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java @@ -17,14 +17,21 @@ */ public class EbeanParsedConfig { + private final Boolean ddlGenerate; private final String defaultDatasource; private final Map> datasourceModels; - public EbeanParsedConfig(String defaultDatasource, Map> datasourceModels) { + public EbeanParsedConfig( + Boolean ddlGenerate, String defaultDatasource, Map> datasourceModels) { + this.ddlGenerate = ddlGenerate; this.defaultDatasource = defaultDatasource; this.datasourceModels = datasourceModels; } + public Boolean getDdlGenerate() { + return ddlGenerate; + } + public String getDefaultDatasource() { return defaultDatasource; } @@ -42,8 +49,9 @@ public Map> getDatasourceModels() { */ public static EbeanParsedConfig parseFromConfig(Config config) { Config playEbeanConfig = config.getConfig("play.ebean"); - String defaultDatasource = playEbeanConfig.getString("defaultDatasource"); String ebeanConfigKey = playEbeanConfig.getString("config"); + Boolean ebeanDdlGenerateKey = playEbeanConfig.getBoolean("ddlGenerate"); + String ebeanDefaultDatasourceKey = playEbeanConfig.getString("defaultDatasource"); Map> datasourceModels = new HashMap<>(); @@ -64,6 +72,6 @@ public static EbeanParsedConfig parseFromConfig(Config config) { datasourceModels.put(key, models); }); } - return new EbeanParsedConfig(defaultDatasource, datasourceModels); + return new EbeanParsedConfig(ebeanDdlGenerateKey, ebeanDefaultDatasourceKey, datasourceModels); } } diff --git a/play-ebean/src/main/resources/reference.conf b/play-ebean/src/main/resources/reference.conf index 530ad5aa..e2864902 100644 --- a/play-ebean/src/main/resources/reference.conf +++ b/play-ebean/src/main/resources/reference.conf @@ -7,6 +7,9 @@ play { # The key for ebean config config = "ebean" + # The key to control the generation of the evolution SQL files + ddlGenerate = true + # The name of the default ebean datasource defaultDatasource = "default" } 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..9448eb05 100644 --- a/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java +++ b/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java @@ -24,6 +24,7 @@ private EbeanParsedConfig parse(Map config) { @Test public void defaultConfig() { EbeanParsedConfig config = parse(Collections.emptyMap()); + assertThat(config.getDdlGenerate(), equalTo(Boolean.TRUE)); assertThat(config.getDefaultDatasource(), equalTo("default")); assertThat(config.getDatasourceModels().size(), equalTo(0)); } @@ -52,6 +53,12 @@ public void customDefault() { assertThat(config.getDefaultDatasource(), equalTo("custom")); } + @Test + public void disableDdlGenerate() { + EbeanParsedConfig config = parse(ImmutableMap.of("play.ebean.ddlGenerate", false)); + assertThat(config.getDdlGenerate(), equalTo(Boolean.FALSE)); + } + @Test public void customConfig() { EbeanParsedConfig config = From 3352d9d2622c7b7a2c3336e6d855726982e67add Mon Sep 17 00:00:00 2001 From: Vadim Vera Date: Thu, 11 Jan 2024 15:56:03 -0500 Subject: [PATCH 2/4] Rename field to generateEvolutionsScripts and adjust references accordingly (cherry picked from commit 6ecdb54af36842ed8ff55e3a8dd07b136a73e922) --- .../play/db/ebean/DefaultEbeanConfig.java | 29 ++++++++++++------- .../main/java/play/db/ebean/EbeanConfig.java | 4 +-- .../play/db/ebean/EbeanDynamicEvolutions.java | 2 +- .../java/play/db/ebean/EbeanParsedConfig.java | 27 +++++++++++------ play-ebean/src/main/resources/reference.conf | 6 ++-- .../play/db/ebean/EbeanParsedConfigTest.java | 9 +++--- 6 files changed, 48 insertions(+), 29 deletions(-) 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 d121cfc5..ccb71863 100644 --- a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java @@ -24,22 +24,23 @@ /** Ebean server configuration. */ @Singleton public class DefaultEbeanConfig implements EbeanConfig { - private final Boolean ddlGenerate; - private final String defaultServer; private final Map serverConfigs; + private final Boolean generateEvolutionsScripts; + public DefaultEbeanConfig( - Boolean ddlGenerate, String defaultServer, Map serverConfigs) { - this.ddlGenerate = ddlGenerate; + String defaultServer, + Map serverConfigs, + Boolean generateEvolutionsScripts) { this.defaultServer = defaultServer; this.serverConfigs = serverConfigs; + this.generateEvolutionsScripts = generateEvolutionsScripts; } - @Override - public Boolean ddlGenerate() { - return ddlGenerate; + public DefaultEbeanConfig(String defaultServer, Map serverConfigs) { + this(defaultServer, serverConfigs, true); } @Override @@ -52,14 +53,20 @@ public Map serverConfigs() { return serverConfigs; } + @Override + public Boolean generateEvolutionsScripts() { + return generateEvolutionsScripts; + } + @Singleton public static class EbeanConfigParser implements Provider { + private static final Logger.ALogger LOGGER = Logger.of(DefaultEbeanConfig.class); private final Config config; + private final Environment environment; - private final DBApi dbApi; - private static final Logger.ALogger LOGGER = Logger.of(DefaultEbeanConfig.class); + private final DBApi dbApi; @Inject public EbeanConfigParser(Config config, Environment environment, DBApi dbApi) { @@ -109,7 +116,9 @@ public EbeanConfig parse() { } return new DefaultEbeanConfig( - ebeanConfig.getDdlGenerate(), ebeanConfig.getDefaultDatasource(), serverConfigs); + 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 b1d9ec3b..f28bf293 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java @@ -8,9 +8,9 @@ import java.util.Map; public interface EbeanConfig { - Boolean ddlGenerate(); - 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 7a870725..8fda66be 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java @@ -64,7 +64,7 @@ public void create() { if (environment.isProd()) { return; } - if (config.ddlGenerate().equals(Boolean.FALSE)) { + if (Boolean.FALSE.equals(config.generateEvolutionsScripts())) { return; } config 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 613741ce..25631f63 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java @@ -16,20 +16,23 @@ * database connection pools to create. */ public class EbeanParsedConfig { - - private final Boolean ddlGenerate; private final String defaultDatasource; + private final Map> datasourceModels; + private final Boolean generateEvolutionsScripts; + public EbeanParsedConfig( - Boolean ddlGenerate, String defaultDatasource, Map> datasourceModels) { - this.ddlGenerate = ddlGenerate; + String defaultDatasource, + Map> datasourceModels, + Boolean generateEvolutionsScripts) { this.defaultDatasource = defaultDatasource; this.datasourceModels = datasourceModels; + this.generateEvolutionsScripts = generateEvolutionsScripts; } - public Boolean getDdlGenerate() { - return ddlGenerate; + public EbeanParsedConfig(String defaultDatasource, Map> datasourceModels) { + this(defaultDatasource, datasourceModels, true); } public String getDefaultDatasource() { @@ -40,6 +43,10 @@ public Map> getDatasourceModels() { return datasourceModels; } + public Boolean generateEvolutionsScripts() { + return generateEvolutionsScripts; + } + /** * Parse a play configuration. * @@ -50,8 +57,9 @@ public Map> getDatasourceModels() { public static EbeanParsedConfig parseFromConfig(Config config) { Config playEbeanConfig = config.getConfig("play.ebean"); String ebeanConfigKey = playEbeanConfig.getString("config"); - Boolean ebeanDdlGenerateKey = playEbeanConfig.getBoolean("ddlGenerate"); - String ebeanDefaultDatasourceKey = playEbeanConfig.getString("defaultDatasource"); + String ebeanDefaultDatasource = playEbeanConfig.getString("defaultDatasource"); + Boolean ebeanGenerateEvolutionsScripts = + playEbeanConfig.getBoolean("generateEvolutionsScripts"); Map> datasourceModels = new HashMap<>(); @@ -72,6 +80,7 @@ public static EbeanParsedConfig parseFromConfig(Config config) { datasourceModels.put(key, models); }); } - return new EbeanParsedConfig(ebeanDdlGenerateKey, ebeanDefaultDatasourceKey, datasourceModels); + return new EbeanParsedConfig( + ebeanDefaultDatasource, datasourceModels, ebeanGenerateEvolutionsScripts); } } diff --git a/play-ebean/src/main/resources/reference.conf b/play-ebean/src/main/resources/reference.conf index e2864902..dfce38b9 100644 --- a/play-ebean/src/main/resources/reference.conf +++ b/play-ebean/src/main/resources/reference.conf @@ -7,10 +7,10 @@ play { # The key for ebean config config = "ebean" - # The key to control the generation of the evolution SQL files - ddlGenerate = true - # 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 9448eb05..fd899695 100644 --- a/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java +++ b/play-ebean/src/test/java/play/db/ebean/EbeanParsedConfigTest.java @@ -24,9 +24,9 @@ private EbeanParsedConfig parse(Map config) { @Test public void defaultConfig() { EbeanParsedConfig config = parse(Collections.emptyMap()); - assertThat(config.getDdlGenerate(), equalTo(Boolean.TRUE)); assertThat(config.getDefaultDatasource(), equalTo("default")); assertThat(config.getDatasourceModels().size(), equalTo(0)); + assertThat(config.generateEvolutionsScripts(), equalTo(Boolean.TRUE)); } @Test @@ -54,9 +54,10 @@ public void customDefault() { } @Test - public void disableDdlGenerate() { - EbeanParsedConfig config = parse(ImmutableMap.of("play.ebean.ddlGenerate", false)); - assertThat(config.getDdlGenerate(), equalTo(Boolean.FALSE)); + public void disableGenerateEvolutionsScripts() { + EbeanParsedConfig config = + parse(ImmutableMap.of("play.ebean.generateEvolutionsScripts", false)); + assertThat(config.generateEvolutionsScripts(), equalTo(Boolean.FALSE)); } @Test From c9e8a83160caad699bc34ed2df114dfa40bc855c Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Tue, 16 Jan 2024 13:54:02 +0100 Subject: [PATCH 3/4] Lets use boolean instead of Boolean wrapper (cherry picked from commit c54a39b0aedc217ad8f65ee820f6a6918aed2268) --- .../java/play/db/ebean/DefaultEbeanConfig.java | 11 +++++++---- .../src/main/java/play/db/ebean/EbeanConfig.java | 3 ++- .../play/db/ebean/EbeanDynamicEvolutions.java | 2 +- .../java/play/db/ebean/EbeanParsedConfig.java | 15 +++++++-------- 4 files changed, 17 insertions(+), 14 deletions(-) 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 ccb71863..e7fe4349 100644 --- a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java @@ -24,16 +24,17 @@ /** Ebean server configuration. */ @Singleton public class DefaultEbeanConfig implements EbeanConfig { + private final String defaultServer; private final Map serverConfigs; - private final Boolean generateEvolutionsScripts; + private final boolean generateEvolutionsScripts; public DefaultEbeanConfig( String defaultServer, Map serverConfigs, - Boolean generateEvolutionsScripts) { + boolean generateEvolutionsScripts) { this.defaultServer = defaultServer; this.serverConfigs = serverConfigs; this.generateEvolutionsScripts = generateEvolutionsScripts; @@ -54,13 +55,12 @@ public Map serverConfigs() { } @Override - public Boolean generateEvolutionsScripts() { + public boolean generateEvolutionsScripts() { return generateEvolutionsScripts; } @Singleton public static class EbeanConfigParser implements Provider { - private static final Logger.ALogger LOGGER = Logger.of(DefaultEbeanConfig.class); private final Config config; @@ -68,6 +68,8 @@ public static class EbeanConfigParser implements Provider { private final DBApi dbApi; + private static final Logger.ALogger LOGGER = Logger.of(DefaultEbeanConfig.class); + @Inject public EbeanConfigParser(Config config, Environment environment, DBApi dbApi) { this.config = config; @@ -86,6 +88,7 @@ public EbeanConfig get() { * @return a config for Ebean servers. */ public EbeanConfig parse() { + EbeanParsedConfig ebeanConfig = EbeanParsedConfig.parseFromConfig(config); Map serverConfigs = new HashMap<>(); 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 f28bf293..f2a2b4f2 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanConfig.java @@ -8,9 +8,10 @@ import java.util.Map; public interface EbeanConfig { + String defaultServer(); Map serverConfigs(); - Boolean generateEvolutionsScripts(); + 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 8fda66be..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,7 +64,7 @@ public void create() { if (environment.isProd()) { return; } - if (Boolean.FALSE.equals(config.generateEvolutionsScripts())) { + if (!config.generateEvolutionsScripts()) { return; } config 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 25631f63..941e7bf0 100644 --- a/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java @@ -16,16 +16,17 @@ * database connection pools to create. */ public class EbeanParsedConfig { + private final String defaultDatasource; private final Map> datasourceModels; - private final Boolean generateEvolutionsScripts; + private final boolean generateEvolutionsScripts; public EbeanParsedConfig( String defaultDatasource, Map> datasourceModels, - Boolean generateEvolutionsScripts) { + boolean generateEvolutionsScripts) { this.defaultDatasource = defaultDatasource; this.datasourceModels = datasourceModels; this.generateEvolutionsScripts = generateEvolutionsScripts; @@ -43,7 +44,7 @@ public Map> getDatasourceModels() { return datasourceModels; } - public Boolean generateEvolutionsScripts() { + public boolean generateEvolutionsScripts() { return generateEvolutionsScripts; } @@ -56,10 +57,9 @@ public Boolean generateEvolutionsScripts() { */ public static EbeanParsedConfig parseFromConfig(Config config) { Config playEbeanConfig = config.getConfig("play.ebean"); + String defaultDatasource = playEbeanConfig.getString("defaultDatasource"); String ebeanConfigKey = playEbeanConfig.getString("config"); - String ebeanDefaultDatasource = playEbeanConfig.getString("defaultDatasource"); - Boolean ebeanGenerateEvolutionsScripts = - playEbeanConfig.getBoolean("generateEvolutionsScripts"); + boolean generateEvolutionsScripts = playEbeanConfig.getBoolean("generateEvolutionsScripts"); Map> datasourceModels = new HashMap<>(); @@ -80,7 +80,6 @@ public static EbeanParsedConfig parseFromConfig(Config config) { datasourceModels.put(key, models); }); } - return new EbeanParsedConfig( - ebeanDefaultDatasource, datasourceModels, ebeanGenerateEvolutionsScripts); + return new EbeanParsedConfig(defaultDatasource, datasourceModels, generateEvolutionsScripts); } } From ee65916795e28a6ac4eca0b59fe3cd020cd2ac89 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Tue, 16 Jan 2024 14:02:45 +0100 Subject: [PATCH 4/4] Add MiMa filters (cherry picked from commit f5a5e227f80c647ff87276709e014bc77a1d2723) --- build.sbt | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sbt b/build.sbt index 48bd4c1b..1bf00b4a 100644 --- a/build.sbt +++ b/build.sbt @@ -23,6 +23,7 @@ val previousVersion: Option[String] = Some("7.0.0") lazy val mimaSettings = Seq( mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet, mimaBinaryIssueFilters ++= Seq( + ProblemFilters.exclude[ReversedMissingMethodProblem]("play.db.ebean.EbeanConfig.generateEvolutionsScripts"), ) )