Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce configuration parameter to control the generation of the evolution SQL files #433

Merged
merged 4 commits into from Jan 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lets use boolean instead of Boolean wrapper
mkurz committed Jan 16, 2024

Verified

This commit was signed with the committer’s verified signature.
mkurz Matthias Kurz
commit c54a39b0aedc217ad8f65ee820f6a6918aed2268
11 changes: 7 additions & 4 deletions play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java
Original file line number Diff line number Diff line change
@@ -24,16 +24,17 @@
/** Ebean server configuration. */
@Singleton
public class DefaultEbeanConfig implements EbeanConfig {

private final String defaultServer;

private final Map<String, DatabaseConfig> serverConfigs;

private final Boolean generateEvolutionsScripts;
private final boolean generateEvolutionsScripts;

public DefaultEbeanConfig(
String defaultServer,
Map<String, DatabaseConfig> serverConfigs,
Boolean generateEvolutionsScripts) {
boolean generateEvolutionsScripts) {
this.defaultServer = defaultServer;
this.serverConfigs = serverConfigs;
this.generateEvolutionsScripts = generateEvolutionsScripts;
@@ -54,20 +55,21 @@ public Map<String, DatabaseConfig> serverConfigs() {
}

@Override
public Boolean generateEvolutionsScripts() {
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);

@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<String, DatabaseConfig> serverConfigs = new HashMap<>();
3 changes: 2 additions & 1 deletion play-ebean/src/main/java/play/db/ebean/EbeanConfig.java
Original file line number Diff line number Diff line change
@@ -8,9 +8,10 @@
import java.util.Map;

public interface EbeanConfig {

String defaultServer();

Map<String, DatabaseConfig> serverConfigs();

Boolean generateEvolutionsScripts();
boolean generateEvolutionsScripts();
}
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public void create() {
if (environment.isProd()) {
return;
}
if (Boolean.FALSE.equals(config.generateEvolutionsScripts())) {
if (!config.generateEvolutionsScripts()) {
return;
}
config
15 changes: 7 additions & 8 deletions play-ebean/src/main/java/play/db/ebean/EbeanParsedConfig.java
Original file line number Diff line number Diff line change
@@ -16,16 +16,17 @@
* database connection pools to create.
*/
public class EbeanParsedConfig {

private final String defaultDatasource;

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

private final Boolean generateEvolutionsScripts;
private final boolean generateEvolutionsScripts;

public EbeanParsedConfig(
String defaultDatasource,
Map<String, List<String>> datasourceModels,
Boolean generateEvolutionsScripts) {
boolean generateEvolutionsScripts) {
this.defaultDatasource = defaultDatasource;
this.datasourceModels = datasourceModels;
this.generateEvolutionsScripts = generateEvolutionsScripts;
@@ -43,7 +44,7 @@ public Map<String, List<String>> 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<String, List<String>> 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);
}
}