Merge pull request #9862 from candrews:patch-6

* pr/9862:
  Polish "Use configured schema in Liquibase endpoint"
  Use configured schema in Liquibase endpoint
pull/9893/merge
Stephane Nicoll 7 years ago
commit 3bc9718cc4

@ -32,6 +32,7 @@ import liquibase.integration.spring.SpringLiquibase;
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.
@ -67,6 +68,10 @@ public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
try {
Database database = factory
.findCorrectDatabaseImplementation(connection);
String defaultSchema = entry.getValue().getDefaultSchema();
if (StringUtils.hasText(defaultSchema)) {
database.setDefaultSchemaName(defaultSchema);
}
reports.add(new LiquibaseReport(entry.getKey(),
service.queryDatabaseChangeLogTable(database)));
}

@ -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.
@ -19,8 +19,10 @@ package org.springframework.boot.actuate.endpoint;
import liquibase.integration.spring.SpringLiquibase;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
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;
import org.springframework.context.annotation.Import;
@ -44,8 +46,20 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
assertThat(getEndpointBean().invoke()).hasSize(1);
}
@Test
public void invokeWithCustomSchema() throws Exception {
this.context = new AnnotationConfigApplicationContext();
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);
}
@Configuration
@Import({ EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class })
@Import({ DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class })
public static class Config {
private final SpringLiquibase liquibase;

Loading…
Cancel
Save