-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you time to provide this pull request.
Some things need to be changed, please refer my comments. Specially we need to keep binary compatibility so I can release that as new minor or patch release without breaking user code.
Thanks!
@@ -24,15 +24,24 @@ | |||
/** Ebean server configuration. */ | |||
@Singleton | |||
public class DefaultEbeanConfig implements EbeanConfig { | |||
private final Boolean ddlGenerate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this variable (and the config key, etc.) to
private final Boolean ddlGenerate; | |
private final Boolean generateEvolutionsScripts; |
public DefaultEbeanConfig( | ||
Boolean ddlGenerate, String defaultServer, Map<String, DatabaseConfig> serverConfigs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to put the new parameter last:
public DefaultEbeanConfig( | |
Boolean ddlGenerate, String defaultServer, Map<String, DatabaseConfig> serverConfigs) { | |
public DefaultEbeanConfig( | |
String defaultServer, Map<String, DatabaseConfig> serverConfigs, Boolean generateEvolutionsScripts) { |
Also, you can see the binary compatibility checks are failing, because you bascially removed a constructor. So you we have to keep that constructor to not break any user code. Please re-add it like:
public DefaultEbeanConfig(String defaultServer, Map<String, DatabaseConfig> serverConfigs) {
this(defaultServer, serverConfigs, true);
}
This will just call the new constructor, keeping generating the evolutions files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I didn't quite understood what this was all about.
@Override | ||
public Boolean ddlGenerate() { | ||
return ddlGenerate; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method now needs to be renamed as well.
@@ -8,6 +8,7 @@ | |||
import java.util.Map; | |||
|
|||
public interface EbeanConfig { | |||
Boolean ddlGenerate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename as well.
@@ -64,6 +64,9 @@ public void create() { | |||
if (environment.isProd()) { | |||
return; | |||
} | |||
if (config.ddlGenerate().equals(Boolean.FALSE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bad practice, you should call equals
on Boolean.FALSE
because it will never be null. Right now you risk running into a NullPointerException
in case config.ddlGenerate()
would return null
. See:
jshell> Boolean foo = null;
foo ==> null
jshell> Boolean.FALSE.equals(foo); // good practice
$2 ==> false
jshell> foo.equals(Boolean.FALSE); // bad practice
| Exception java.lang.NullPointerException
| at (#3:1)
So your code should end up like:
if (config.ddlGenerate().equals(Boolean.FALSE)) { | |
if (Boolean.FALSE.equals(config.generateEvolutionsScripts())) { |
public EbeanParsedConfig(String defaultDatasource, Map<String, List<String>> datasourceModels) { | ||
public EbeanParsedConfig( | ||
Boolean ddlGenerate, String defaultDatasource, Map<String, List<String>> datasourceModels) { | ||
this.ddlGenerate = ddlGenerate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor is the same story I described before at the other constructor, please follow what I described there also, thanks!
this.defaultDatasource = defaultDatasource; | ||
this.datasourceModels = datasourceModels; | ||
} | ||
|
||
public Boolean getDdlGenerate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename.
String ebeanConfigKey = playEbeanConfig.getString("config"); | ||
Boolean ebeanDdlGenerateKey = playEbeanConfig.getBoolean("ddlGenerate"); | ||
String ebeanDefaultDatasourceKey = playEbeanConfig.getString("defaultDatasource"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not add a ...Key
suffix to the variable names here. I see you did that because of how ebeanConfigKey
is named, but this is different, because ebeanConfigKey
actually really contains a config key, but the other variables do not, they contain actual values.
So please for the two variables, remove the ...Key
suffix (and rename the new var accordingly).
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename.
I see the pipeline failing with this error: |
Yeah that's because EbeanConfig is an interface and MiMa complains that now all subclasses need to define that method. We can't really work around that. I pushed a commit to use a primitive boolean instead of the wrapper. Will release 8.1.0 in a minute. |
@Mergifyio backport 7.0.x |
✅ Backports have been created
|
[7.0.x] Introduce configuration parameter to control the generation of the evolution SQL files (backport #433) by @vadimvera
Does default method not help? |
Closes #366