Skip to content

Allow forcing DataSourceClosingSpringLiquibase when manually defining a @LiquibaseDataSource #18126

@Tristan971

Description

@Tristan971

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions