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

Skip connection for datasources with omitted db configuration #403

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

hertg
Copy link
Contributor

@hertg hertg commented Oct 3, 2023

This change will prevent issue #402 by skipping the creation and registration of a DatabaseConfig for ebean datasources which have no db connection parameters configured.

With this PR, users are able to specify and enhance Ebean models for datasources that may not be available on application startup, or that may be connected at a later stage during runtime. The ebean.<datasource> configuration can be specified without the need to also specify db.<datasource>.

play.evolutions.db.foo.enabled = false
ebean.foo = ["models.foo.*"]

// NOT CONFIGURED
// db.foo { 
// }

After a few tests, this seems to behave as I'd expect.

  • Trying to query a model that was skipped will lead to the DataSource user is null? exception
  • Once a connection is establised manually (see below), querying the model becomes possible
// manually connect the datasource
final DataSourceConfig dsc = new DataSourceConfig();
dsc.setUsername("username");
dsc.setPassword("password");
dsc.setUrl(connectionString("localhost", "my_schema");
final DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setDataSourceConfig(dsc);
databaseConfig.setName("foo");
databaseConfig.setDefaultServer(false);
DatabaseFactory.create(databaseConfig);

I added a Logger to print information about the server config being skipped. I was not able to find a reference on how this should be done, so I did it the same way I'd do it in a Play application, by using play.Logger.ALogger. Let me know if this needs change.

@hertg hertg changed the title Skip creation of ServerConfig Skip connection for datasources with omitted db configuration Oct 3, 2023
@mkurz mkurz merged commit 1156ded into playframework:main Oct 4, 2023
20 checks passed
@ihostage
Copy link
Member

@Mergifyio backport 7.0.x

@mergify
Copy link
Contributor

mergify bot commented Oct 17, 2023

backport 7.0.x

✅ Backports have been created

mkurz added a commit that referenced this pull request Oct 17, 2023
[7.0.x] Skip connection for datasources with omitted db configuration (backport #403) by @hertg
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.

3 participants