Polish "Use configured schema in Liquibase endpoint"
Closes gh-9862
This commit is contained in:
parent
3e13970fe0
commit
7e21178f63
|
|
@ -28,11 +28,11 @@ import liquibase.database.Database;
|
|||
import liquibase.database.DatabaseFactory;
|
||||
import liquibase.database.jvm.JdbcConnection;
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
import liquibase.util.StringUtils;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link Endpoint} to expose liquibase info.
|
||||
|
|
@ -69,7 +69,7 @@ public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
|
|||
Database database = factory
|
||||
.findCorrectDatabaseImplementation(connection);
|
||||
String defaultSchema = entry.getValue().getDefaultSchema();
|
||||
if (StringUtils.trimToNull(defaultSchema) != null) {
|
||||
if (StringUtils.hasText(defaultSchema)) {
|
||||
database.setDefaultSchemaName(defaultSchema);
|
||||
}
|
||||
reports.add(new LiquibaseReport(entry.getKey(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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,9 +18,10 @@ package org.springframework.boot.actuate.endpoint;
|
|||
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -46,13 +47,12 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
|
|||
}
|
||||
|
||||
@Test
|
||||
public void invokeDifferentDefaultSchema() throws Exception {
|
||||
public void invokeWithCustomSchema() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues
|
||||
.ofPair("liquibase.defaultSchema","SOMESCHEMA")
|
||||
.and("spring.datasource.generate-unique-name","true")
|
||||
.and("spring.datasource.schema","classpath:/db/non-default-schema.sql")
|
||||
.applyTo(this.context);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"liquibase.default-schema=CUSTOMSCHEMA",
|
||||
"spring.datasource.generate-unique-name=true",
|
||||
"spring.datasource.schema=classpath:/db/create-custom-schema.sql");
|
||||
this.context.register(Config.class);
|
||||
this.context.refresh();
|
||||
assertThat(getEndpointBean().invoke()).hasSize(1);
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
CREATE SCHEMA CUSTOMSCHEMA;
|
||||
|
|
@ -1 +0,0 @@
|
|||
CREATE SCHEMA SOMESCHEMA;
|
||||
Loading…
Reference in New Issue