Skip to content

Commit

Permalink
Rename field to generateEvolutionsScripts and adjust references accor…
Browse files Browse the repository at this point in the history
…dingly

(cherry picked from commit 6ecdb54)
  • Loading branch information
Vadim Vera authored and mergify[bot] committed Jan 16, 2024
1 parent d810de4 commit 3352d9d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 29 deletions.
29 changes: 19 additions & 10 deletions play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@
/** Ebean server configuration. */
@Singleton
public class DefaultEbeanConfig implements EbeanConfig {
private final Boolean ddlGenerate;

private final String defaultServer;

private final Map<String, DatabaseConfig> serverConfigs;

private final Boolean generateEvolutionsScripts;

public DefaultEbeanConfig(
Boolean ddlGenerate, String defaultServer, Map<String, DatabaseConfig> serverConfigs) {
this.ddlGenerate = ddlGenerate;
String defaultServer,
Map<String, DatabaseConfig> serverConfigs,
Boolean generateEvolutionsScripts) {
this.defaultServer = defaultServer;
this.serverConfigs = serverConfigs;
this.generateEvolutionsScripts = generateEvolutionsScripts;
}

@Override
public Boolean ddlGenerate() {
return ddlGenerate;
public DefaultEbeanConfig(String defaultServer, Map<String, DatabaseConfig> serverConfigs) {
this(defaultServer, serverConfigs, true);
}

@Override
Expand All @@ -52,14 +53,20 @@ public Map<String, DatabaseConfig> serverConfigs() {
return serverConfigs;
}

@Override
public Boolean generateEvolutionsScripts() {
return generateEvolutionsScripts;
}

@Singleton
public static class EbeanConfigParser implements Provider<EbeanConfig> {
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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions play-ebean/src/main/java/play/db/ebean/EbeanConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import java.util.Map;

public interface EbeanConfig {
Boolean ddlGenerate();

String defaultServer();

Map<String, DatabaseConfig> serverConfigs();

Boolean generateEvolutionsScripts();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
* database connection pools to create.
*/
public class EbeanParsedConfig {

private final Boolean ddlGenerate;
private final String defaultDatasource;

private final Map<String, List<String>> datasourceModels;

private final Boolean generateEvolutionsScripts;

public EbeanParsedConfig(
Boolean ddlGenerate, String defaultDatasource, Map<String, List<String>> datasourceModels) {
this.ddlGenerate = ddlGenerate;
String defaultDatasource,
Map<String, List<String>> datasourceModels,
Boolean generateEvolutionsScripts) {
this.defaultDatasource = defaultDatasource;
this.datasourceModels = datasourceModels;
this.generateEvolutionsScripts = generateEvolutionsScripts;
}

public Boolean getDdlGenerate() {
return ddlGenerate;
public EbeanParsedConfig(String defaultDatasource, Map<String, List<String>> datasourceModels) {
this(defaultDatasource, datasourceModels, true);
}

public String getDefaultDatasource() {
Expand All @@ -40,6 +43,10 @@ public Map<String, List<String>> getDatasourceModels() {
return datasourceModels;
}

public Boolean generateEvolutionsScripts() {
return generateEvolutionsScripts;
}

/**
* Parse a play configuration.
*
Expand All @@ -50,8 +57,9 @@ public Map<String, List<String>> 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<String, List<String>> datasourceModels = new HashMap<>();

Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions play-ebean/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ private EbeanParsedConfig parse(Map<String, ?> 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3352d9d

Please sign in to comment.