From 8a04e2cc86f8cce8fdd1b6a70e466d393f0733ab Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 4 Apr 2019 14:36:14 +0100 Subject: [PATCH] Honor custom change log tables in Liquibase endpoint Closes gh-16442 --- .../actuate/liquibase/LiquibaseEndpoint.java | 6 ++- .../liquibase/LiquibaseEndpointTests.java | 40 ++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpoint.java index 914deabd68..65a5ca1f3c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,6 +87,10 @@ public class LiquibaseEndpoint { if (StringUtils.hasText(defaultSchema)) { database.setDefaultSchemaName(defaultSchema); } + database.setDatabaseChangeLogTableName( + liquibase.getDatabaseChangeLogTable()); + database.setDatabaseChangeLogLockTableName( + liquibase.getDatabaseChangeLogLockTable()); service.setDatabase(database); return new LiquibaseBean(service.getRanChangeSets().stream() .map(ChangeSet::new).collect(Collectors.toList())); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java index b713ca21f2..3e01b8006c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,13 @@ package org.springframework.boot.actuate.liquibase; import java.sql.Connection; import java.sql.SQLException; +import java.util.Map; import javax.sql.DataSource; import org.junit.Test; +import org.springframework.boot.actuate.liquibase.LiquibaseEndpoint.LiquibaseBean; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; @@ -49,11 +51,12 @@ public class LiquibaseEndpointTests { @Test public void liquibaseReportIsReturned() { - this.contextRunner.withUserConfiguration(Config.class) - .run((context) -> assertThat( - context.getBean(LiquibaseEndpoint.class).liquibaseBeans() - .getContexts().get(context.getId()).getLiquibaseBeans()) - .hasSize(1)); + this.contextRunner.withUserConfiguration(Config.class).run((context) -> { + Map liquibaseBeans = context + .getBean(LiquibaseEndpoint.class).liquibaseBeans().getContexts() + .get(context.getId()).getLiquibaseBeans(); + assertThat(liquibaseBeans.get("liquibase").getChangeSets()).hasSize(1); + }); } @Test @@ -61,10 +64,27 @@ public class LiquibaseEndpointTests { this.contextRunner.withUserConfiguration(Config.class) .withPropertyValues("spring.liquibase.default-schema=CUSTOMSCHEMA", "spring.datasource.schema=classpath:/db/create-custom-schema.sql") - .run((context) -> assertThat( - context.getBean(LiquibaseEndpoint.class).liquibaseBeans() - .getContexts().get(context.getId()).getLiquibaseBeans()) - .hasSize(1)); + .run((context) -> { + Map liquibaseBeans = context + .getBean(LiquibaseEndpoint.class).liquibaseBeans() + .getContexts().get(context.getId()).getLiquibaseBeans(); + assertThat(liquibaseBeans.get("liquibase").getChangeSets()) + .hasSize(1); + }); + } + + @Test + public void invokeWithCustomTables() { + this.contextRunner.withUserConfiguration(Config.class).withPropertyValues( + "spring.liquibase.database-change-log-lock-table=liquibase_database_changelog_lock", + "spring.liquibase.database-change-log-table=liquibase_database_changelog") + .run((context) -> { + Map liquibaseBeans = context + .getBean(LiquibaseEndpoint.class).liquibaseBeans() + .getContexts().get(context.getId()).getLiquibaseBeans(); + assertThat(liquibaseBeans.get("liquibase").getChangeSets()) + .hasSize(1); + }); } @Test