-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
Hello, this is an enhancement suggestion (which I'm happy to implement as well but wanted to make sure there's not a good reason that it was not done before prior to working on it).
As part of #9218, the DataSourceClosingSpringLiquibase class was added.
This allows closing the connection pool once the liquibase migrations are applied (in case of Liquibase being ran on application startup mostly) instead of hanging around for the whole application lifecycle.
Unfortunately it is only auto-configured (instead of the standard SpringLiquibase) if no DataSource has been configured with @LiquibaseDataSource annotated on it, as that datasource would be autowired here:
Lines 82 to 90 in a6f8351
| public LiquibaseConfiguration(LiquibaseProperties properties, | |
| ResourceLoader resourceLoader, | |
| ObjectProvider<DataSource> dataSourceProvider, | |
| @LiquibaseDataSource ObjectProvider<DataSource> liquibaseDataSource) { | |
| this.properties = properties; | |
| this.resourceLoader = resourceLoader; | |
| this.dataSource = dataSourceProvider.getIfUnique(); | |
| this.liquibaseDataSource = liquibaseDataSource.getIfAvailable(); | |
| } |
and yield the "standard" branch here:
Lines 118 to 129 in a6f8351
| private SpringLiquibase createSpringLiquibase() { | |
| SpringLiquibase liquibase; | |
| DataSource dataSource = getDataSource(); | |
| if (dataSource == null) { | |
| dataSource = DataSourceBuilder.create().url(this.properties.getUrl()) | |
| .username(this.properties.getUser()) | |
| .password(this.properties.getPassword()).build(); | |
| liquibase = new DataSourceClosingSpringLiquibase(); | |
| } | |
| else { | |
| liquibase = new SpringLiquibase(); | |
| } |
The proposal is to allow forcing DataSourceClosingSpringLiquibase through a property of LiquibaseProperties.
Probably something like closeDataSourceOnceMigrated as it's already named in DataSourceClosingSpringLiquibase itself right now and overriden in LiquibaseEndpointAutoConfiguration#preventDataSourceCloseBeanPostProcessor if the Liquibase endpoint is enabled.
As for the motivation, it would allow more customization of the underlying DataSource used. So we could set hikari-level configuration that is specific to the Liquibase pool, (pool name, max pool size... and other such things as we already do for other DataSource instances) without having to share it with other "post-initialization" datasources.
Thank you