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.
|
* {@link Endpoint @Endpoint} to expose liquibase info.
|
||||||
*
|
*
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
|
* @author Nabil Fawwaz Elqayyim
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Endpoint(id = "liquibase")
|
@Endpoint(id = "liquibase")
|
||||||
|
@ -79,9 +80,12 @@ public class LiquibaseEndpoint {
|
||||||
Database database = null;
|
Database database = null;
|
||||||
try {
|
try {
|
||||||
database = factory.findCorrectDatabaseImplementation(connection);
|
database = factory.findCorrectDatabaseImplementation(connection);
|
||||||
String defaultSchema = liquibase.getDefaultSchema();
|
String schemaToUse = liquibase.getLiquibaseSchema();
|
||||||
if (StringUtils.hasText(defaultSchema)) {
|
if (!StringUtils.hasText(schemaToUse)) { // Use liquibase-schema if set, otherwise fall back to default-schema
|
||||||
database.setDefaultSchemaName(defaultSchema);
|
schemaToUse = liquibase.getDefaultSchema();
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(schemaToUse)) {
|
||||||
|
database.setDefaultSchemaName(schemaToUse);
|
||||||
}
|
}
|
||||||
database.setDatabaseChangeLogTableName(liquibase.getDatabaseChangeLogTable());
|
database.setDatabaseChangeLogTableName(liquibase.getDatabaseChangeLogTable());
|
||||||
database.setDatabaseChangeLogLockTableName(liquibase.getDatabaseChangeLogLockTable());
|
database.setDatabaseChangeLogLockTableName(liquibase.getDatabaseChangeLogLockTable());
|
||||||
|
|
|
@ -50,6 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Leo Li
|
* @author Leo Li
|
||||||
|
* @author Nabil Fawwaz Elqayyim
|
||||||
*/
|
*/
|
||||||
@WithResource(name = "db/changelog/db.changelog-master.yaml", content = """
|
@WithResource(name = "db/changelog/db.changelog-master.yaml", content = """
|
||||||
databaseChangeLog:
|
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
|
@Test
|
||||||
void connectionAutoCommitPropertyIsReset() {
|
void connectionAutoCommitPropertyIsReset() {
|
||||||
this.contextRunner.withUserConfiguration(Config.class).run((context) -> {
|
this.contextRunner.withUserConfiguration(Config.class).run((context) -> {
|
||||||
|
|
Loading…
Reference in New Issue