Skip to content

Separate auto-configuration of script-based DataSource initialization from the auto-configuration of the DataSource #25323

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

Closed
wilkinsona opened this issue Feb 17, 2021 · 4 comments
Assignees
Labels
status: noteworthy A noteworthy issue to call out in the release notes theme: datasource Issues relating to data sources type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Feb 17, 2021

Currently, the auto-configuration of script-based DataSource initialization is intermingled with the auto-configuration of the DataSource itself. This means that the spring.datasource.* properties are a mixture of those that are used to create the DataSource and those that are then used to initialise it using DDL and DML scripts. We should separate out the auto-configuration and the properties that are specific to our script-based initialization.

In addition to making it clearer which properties are for initialization and which are for general data source configuration, this will align the structure of the auto-configuration for our script-based initialization with how things are structured for Flyway and Liquibase.

@wilkinsona wilkinsona added type: enhancement A general enhancement theme: datasource Issues relating to data sources labels Feb 17, 2021
@wilkinsona wilkinsona added this to the 2.5.x milestone Feb 17, 2021
@wilkinsona wilkinsona self-assigned this Feb 17, 2021
@wilkinsona wilkinsona changed the title Separate properties for configuring the DataSource from those used for script-based initialization of the DataSource Separate auto-configuration of script-based DataSource initialization from the auto-configuration of the DataSource Mar 23, 2021
@wilkinsona wilkinsona added the status: noteworthy A noteworthy issue to call out in the release notes label Mar 23, 2021
@wilkinsona
Copy link
Member Author

wilkinsona commented Mar 23, 2021

This issue is noteworthy as all of the spring.datasource properties that are specific to initialization are being deprecated with spring.sql.init replacements. The separate usernames and passwords for schema and data scripts are not being replaced. Instead, the same credentials, configured using spring.sql.init.username and spring.sql.init.password, are used for DDL (schema) and DML (data) scripts. If users need separate credentials for DDL and DML, they can define their own, appropriately configured data source initializer beans.

@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.5.0-RC1 Mar 24, 2021
@wilkinsona
Copy link
Member Author

wilkinsona commented Apr 14, 2021

Re-opening to include SqlInitializationAutoConfiguration in test slices that use JDBC.

@mmatela
Copy link

mmatela commented May 29, 2021

Am I missing something, or does this change make things more complicated for a pretty common scenario?
In our standard configuration the app connects to a postgresql server, so I need to set spring.sql.init.enabled=false so it doesn't try to create tables that already exist.
But now for tests we use @AutoConfigureTestDatabase so that an embedded database is used and the tests fail because the database is empty.
So I would need to change the configuration depending on whether I'm starting the app normally or just running tests. There was no such issue previously.
A workaround for now is to use the deprecated spring.datasource.initialization-mode = embedded, I hope it's not removed any time soon.

Or maybe the @AutoConfigureTestDatabase feature should be changed to force spring.sql.init.enabled=true?

@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label Jun 1, 2021
@philwebb
Copy link
Member

philwebb commented Jun 7, 2021

@mmatela You might want to follow #26682. Another option would be to move your .sql files to src/test/resources rather than src/main/resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: noteworthy A noteworthy issue to call out in the release notes theme: datasource Issues relating to data sources type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants