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

Conversation

ghost
Copy link

@ghost ghost commented Jan 10, 2024

Closes #366

Copy link
Member

@mkurz mkurz left a 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;
Copy link
Member

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

Suggested change
private final Boolean ddlGenerate;
private final Boolean generateEvolutionsScripts;

Comment on lines 33 to 34
public DefaultEbeanConfig(
Boolean ddlGenerate, String defaultServer, Map<String, DatabaseConfig> serverConfigs) {
Copy link
Member

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:

Suggested change
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.

Copy link
Author

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;
}
Copy link
Member

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();
Copy link
Member

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)) {
Copy link
Member

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:

Suggested change
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;
Copy link
Member

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() {
Copy link
Member

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");
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename.

@ghost
Copy link
Author

ghost commented Jan 11, 2024

I see the pipeline failing with this error: abstract method generateEvolutionsScripts()java.lang.Boolean in interface play.db.ebean.EbeanConfig is present only in current, but the EbeanConfig needs to have that new value, right?

@mkurz
Copy link
Member

mkurz commented Jan 16, 2024

I see the pipeline failing with this error: abstract method generateEvolutionsScripts()java.lang.Boolean in interface play.db.ebean.EbeanConfig is present only in current, but the EbeanConfig needs to have that new value, right?

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.
Thanks!

@mkurz mkurz merged commit 2a13870 into playframework:main Jan 16, 2024
20 checks passed
@mkurz
Copy link
Member

mkurz commented Jan 16, 2024

@Mergifyio backport 7.0.x

Copy link
Contributor

mergify bot commented Jan 16, 2024

backport 7.0.x

✅ Backports have been created

mkurz added a commit that referenced this pull request Jan 16, 2024
[7.0.x] Introduce configuration parameter to control the generation of the evolution SQL files (backport #433) by @vadimvera
@ihostage
Copy link
Member

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.

Does default method not help?
It doesn't matter for this, I think. But It's just interesting what behaviour MiMa with adding default method in interface. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

config to disable generation of evolution 1.sql file's
2 participants