Skip to content

Commit 7534f0b

Browse files
committed
Fix LiquibaseEndpoint to respect liquibase-schema property
Signed-off-by: Nabil Fawwaz Elqayyim <[email protected]>
1 parent 3a9ab15 commit 7534f0b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

module/spring-boot-liquibase/src/main/java/org/springframework/boot/liquibase/endpoint/LiquibaseEndpoint.java

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

module/spring-boot-liquibase/src/test/java/org/springframework/boot/liquibase/actuate/endpoint/LiquibaseEndpointTests.java

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

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

0 commit comments

Comments
 (0)