Skip to content

Liquibase actuator endpoint does not give correct information when multiple databases are used in one project #19171

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public ApplicationLiquibaseBeans liquibaseBeans() {
while (target != null) {
Map<String, LiquibaseBean> liquibaseBeans = new HashMap<>();
DatabaseFactory factory = DatabaseFactory.getInstance();
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
this.context.getBeansOfType(SpringLiquibase.class)
.forEach((name, liquibase) -> liquibaseBeans.put(name, createReport(liquibase, service, factory)));
this.context.getBeansOfType(SpringLiquibase.class).forEach((name, liquibase) -> {
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
liquibaseBeans.put(name, createReport(liquibase, service, factory));
});
ApplicationContext parent = target.getParent();
contextBeans.put(target.getId(),
new ContextLiquibaseBeans(liquibaseBeans, (parent != null) ? parent.getId() : null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import javax.sql.DataSource;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import liquibase.integration.spring.SpringLiquibase;
import org.junit.Test;

import org.springframework.boot.actuate.liquibase.LiquibaseEndpoint.LiquibaseBean;
Expand All @@ -41,6 +44,7 @@
* @author Eddú Meléndez
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Leo Li
*/
public class LiquibaseEndpointTests {

Expand Down Expand Up @@ -92,6 +96,20 @@ public void connectionAutoCommitPropertyIsReset() {
});
}

@Test
public void multipleLiquibaseReportIsReturned() {
this.contextRunner.withUserConfiguration(Config.class, LiquibaseConfiguration.class).run((context) -> {
Map<String, LiquibaseBean> liquibaseBeans = context.getBean(LiquibaseEndpoint.class).liquibaseBeans()
.getContexts().get(context.getId()).getLiquibaseBeans();
assertThat(liquibaseBeans.get("liquibase").getChangeSets()).hasSize(1);
assertThat(liquibaseBeans.get("liquibase").getChangeSets().get(0).getChangeLog())
.isEqualTo("classpath:/db/changelog/db.changelog-master.yaml");
assertThat(liquibaseBeans.get("liquibaseBackup").getChangeSets()).hasSize(1);
assertThat(liquibaseBeans.get("liquibaseBackup").getChangeSets().get(0).getChangeLog())
.isEqualTo("classpath:/db/changelog/db.changelog-master-backup.yaml");
});
}

private boolean getAutoCommit(DataSource dataSource) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
return connection.getAutoCommit();
Expand All @@ -108,4 +126,43 @@ public LiquibaseEndpoint endpoint(ApplicationContext context) {

}

@Configuration
static class LiquibaseConfiguration {

@Bean
DataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:hsqldb:mem:test");
config.setUsername("sa");
return new HikariDataSource(config);
}

@Bean
DataSource dataSourceBackup() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:hsqldb:mem:testBackup");
config.setUsername("sa");
return new HikariDataSource(config);
}

@Bean
SpringLiquibase liquibase(DataSource dataSource) {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setChangeLog("classpath:/db/changelog/db.changelog-master.yaml");
liquibase.setShouldRun(true);
liquibase.setDataSource(dataSource);
return liquibase;
}

@Bean
SpringLiquibase liquibaseBackup(DataSource dataSourceBackup) {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setChangeLog("classpath:/db/changelog/db.changelog-master-backup.yaml");
liquibase.setShouldRun(true);
liquibase.setDataSource(dataSourceBackup);
return liquibase;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
databaseChangeLog:
- changeSet:
id: 1
author: leoli
changes:
- createTable:
tableName: customerbackup
columns:
- column:
name: id
type: int
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: name
type: varchar(50)
constraints:
nullable: false