Use liquibase schema in LiquibaseEndpoint if it set
See gh-47300 Signed-off-by: Nabil Fawwaz Elqayyim <master@nabilfawwaz.com>
This commit is contained in:
parent
f93c43cb8a
commit
bdb05639bc
|
@ -43,6 +43,7 @@ import org.springframework.util.StringUtils;
|
|||
* {@link Endpoint @Endpoint} to expose liquibase info.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
* @author Nabil Fawwaz Elqayyim
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Endpoint(id = "liquibase")
|
||||
|
@ -79,9 +80,12 @@ public class LiquibaseEndpoint {
|
|||
Database database = null;
|
||||
try {
|
||||
database = factory.findCorrectDatabaseImplementation(connection);
|
||||
String defaultSchema = liquibase.getDefaultSchema();
|
||||
if (StringUtils.hasText(defaultSchema)) {
|
||||
database.setDefaultSchemaName(defaultSchema);
|
||||
String schemaToUse = liquibase.getLiquibaseSchema();
|
||||
if (!StringUtils.hasText(schemaToUse)) { // Use liquibase-schema if set, otherwise fall back to default-schema
|
||||
schemaToUse = liquibase.getDefaultSchema();
|
||||
}
|
||||
if (StringUtils.hasText(schemaToUse)) {
|
||||
database.setDefaultSchemaName(schemaToUse);
|
||||
}
|
||||
database.setDatabaseChangeLogTableName(liquibase.getDatabaseChangeLogTable());
|
||||
database.setDatabaseChangeLogLockTableName(liquibase.getDatabaseChangeLogLockTable());
|
||||
|
|
|
@ -50,6 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Leo Li
|
||||
* @author Nabil Fawwaz Elqayyim
|
||||
*/
|
||||
@WithResource(name = "db/changelog/db.changelog-master.yaml", content = """
|
||||
databaseChangeLog:
|
||||
|
@ -119,6 +120,21 @@ class LiquibaseEndpointTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithResource(name = "db/create-custom-schema.sql", content = "CREATE SCHEMA LIQUIBASE_SCHEMA;")
|
||||
void invokeWithLiquibaseSchema() {
|
||||
this.contextRunner.withUserConfiguration(Config.class, DataSourceWithSchemaConfiguration.class)
|
||||
.withPropertyValues("spring.liquibase.liquibase-schema=LIQUIBASE_SCHEMA")
|
||||
.run((context) -> {
|
||||
Map<String, LiquibaseBeanDescriptor> liquibaseBeans = context.getBean(LiquibaseEndpoint.class)
|
||||
.liquibaseBeans()
|
||||
.getContexts()
|
||||
.get(context.getId())
|
||||
.getLiquibaseBeans();
|
||||
assertThat(liquibaseBeans.get("liquibase").getChangeSets()).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectionAutoCommitPropertyIsReset() {
|
||||
this.contextRunner.withUserConfiguration(Config.class).run((context) -> {
|
||||
|
|
Loading…
Reference in New Issue