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:
|
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:
|
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
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
DataSourceClosingSpringLiquibaseclass 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 noDataSourcehas been configured with@LiquibaseDataSourceannotated on it, as that datasource would be autowired here:spring-boot/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
Lines 82 to 90 in a6f8351
and yield the "standard" branch here:
spring-boot/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java
Lines 118 to 129 in a6f8351
The proposal is to allow forcing
DataSourceClosingSpringLiquibasethrough a property ofLiquibaseProperties.Probably something like
closeDataSourceOnceMigratedas it's already named inDataSourceClosingSpringLiquibaseitself right now and overriden inLiquibaseEndpointAutoConfiguration#preventDataSourceCloseBeanPostProcessorif the Liquibase endpoint is enabled.As for the motivation, it would allow more customization of the underlying
DataSourceused. 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 otherDataSourceinstances) without having to share it with other "post-initialization" datasources.Thank you