Skip to content

Commit bdb0563

Browse files
xyracliussnicoll
authored andcommitted
Use liquibase schema in LiquibaseEndpoint if it set
See gh-47300 Signed-off-by: Nabil Fawwaz Elqayyim <master@nabilfawwaz.com>
1 parent f93c43c commit bdb0563

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpoint.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* {@link Endpoint @Endpoint} to expose liquibase info.
4444
*
4545
* @author Eddú Meléndez
46+
* @author Nabil Fawwaz Elqayyim
4647
* @since 2.0.0
4748
*/
4849
@Endpoint(id = "liquibase")
@@ -79,9 +80,12 @@ private LiquibaseBeanDescriptor createReport(SpringLiquibase liquibase, Database
7980
Database database = null;
8081
try {
8182
database = factory.findCorrectDatabaseImplementation(connection);
82-
String defaultSchema = liquibase.getDefaultSchema();
83-
if (StringUtils.hasText(defaultSchema)) {
84-
database.setDefaultSchemaName(defaultSchema);
83+
String schemaToUse = liquibase.getLiquibaseSchema();
84+
if (!StringUtils.hasText(schemaToUse)) { // Use liquibase-schema if set, otherwise fall back to default-schema
85+
schemaToUse = liquibase.getDefaultSchema();
86+
}
87+
if (StringUtils.hasText(schemaToUse)) {
88+
database.setDefaultSchemaName(schemaToUse);
8589
}
8690
database.setDatabaseChangeLogTableName(liquibase.getDatabaseChangeLogTable());
8791
database.setDatabaseChangeLogLockTableName(liquibase.getDatabaseChangeLogLockTable());

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* @author Andy Wilkinson
5151
* @author Stephane Nicoll
5252
* @author Leo Li
53+
* @author Nabil Fawwaz Elqayyim
5354
*/
5455
@WithResource(name = "db/changelog/db.changelog-master.yaml", content = """
5556
databaseChangeLog:
@@ -119,6 +120,21 @@ void invokeWithCustomTables() {
119120
});
120121
}
121122

123+
@Test
124+
@WithResource(name = "db/create-custom-schema.sql", content = "CREATE SCHEMA LIQUIBASE_SCHEMA;")
125+
void invokeWithLiquibaseSchema() {
126+
this.contextRunner.withUserConfiguration(Config.class, DataSourceWithSchemaConfiguration.class)
127+
.withPropertyValues("spring.liquibase.liquibase-schema=LIQUIBASE_SCHEMA")
128+
.run((context) -> {
129+
Map<String, LiquibaseBeanDescriptor> liquibaseBeans = context.getBean(LiquibaseEndpoint.class)
130+
.liquibaseBeans()
131+
.getContexts()
132+
.get(context.getId())
133+
.getLiquibaseBeans();
134+
assertThat(liquibaseBeans.get("liquibase").getChangeSets()).hasSize(1);
135+
});
136+
}
137+
122138
@Test
123139
void connectionAutoCommitPropertyIsReset() {
124140
this.contextRunner.withUserConfiguration(Config.class).run((context) -> {

0 commit comments

Comments
 (0)