Skip to content

Add liquibase ui-service property #39227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand All @@ -22,6 +22,7 @@
import liquibase.UpdateSummaryOutputEnum;
import liquibase.change.DatabaseChange;
import liquibase.integration.spring.SpringLiquibase;
import liquibase.ui.UIServiceEnum;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
Expand Down Expand Up @@ -122,6 +123,9 @@ public SpringLiquibase liquibase(ObjectProvider<DataSource> dataSource,
liquibase
.setShowSummaryOutput(UpdateSummaryOutputEnum.valueOf(properties.getShowSummaryOutput().name()));
}
if (properties.getUiService() != null) {
liquibase.setUiService(UIServiceEnum.valueOf(properties.getUiService().name()));
}
return liquibase;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand All @@ -22,6 +22,7 @@
import liquibase.UpdateSummaryEnum;
import liquibase.UpdateSummaryOutputEnum;
import liquibase.integration.spring.SpringLiquibase;
import liquibase.ui.UIServiceEnum;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -147,6 +148,11 @@ public class LiquibaseProperties {
*/
private ShowSummaryOutput showSummaryOutput;

/**
* Which UIService to use.
*/
private UIService uiService;

public String getChangeLog() {
return this.changeLog;
}
Expand Down Expand Up @@ -316,6 +322,14 @@ public void setShowSummaryOutput(ShowSummaryOutput showSummaryOutput) {
this.showSummaryOutput = showSummaryOutput;
}

public UIService getUiService() {
return this.uiService;
}

public void setUiService(UIService uiService) {
this.uiService = uiService;
}

/**
* Enumeration of types of summary to show. Values are the same as those on
* {@link UpdateSummaryEnum}. To maximize backwards compatibility, the Liquibase enum
Expand Down Expand Up @@ -368,4 +382,25 @@ public enum ShowSummaryOutput {

}

/**
* Enumeration of types of UIService. Values are the same as those on
* {@link UIServiceEnum}. To maximize backwards compatibility, the Liquibase enum is
* not used directly.
*
* @since 3.3.0
*/
public enum UIService {

/**
* Console-based UIService.
*/
CONSOLE,

/**
* Logging-based UIService.
*/
LOGGER

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,10 @@
"name": "spring.liquibase.show-summary-output",
"defaultValue": "log"
},
{
"name": "spring.liquibase.ui-service",
"defaultValue": "logger"
},
{
"name": "spring.mail.test-connection",
"description": "Whether to test that the mail server is available on startup.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -33,6 +33,7 @@
import liquibase.UpdateSummaryOutputEnum;
import liquibase.command.core.helpers.ShowSummaryArgument;
import liquibase.integration.spring.SpringLiquibase;
import liquibase.ui.UIServiceEnum;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -226,6 +227,7 @@ void defaultValues() {
assertThat(liquibase).extracting("showSummary").isNull();
assertThat(ShowSummaryArgument.SHOW_SUMMARY.getDefaultValue()).isEqualTo(UpdateSummaryEnum.SUMMARY);
assertThat(liquibase).extracting("showSummaryOutput").isEqualTo(UpdateSummaryOutputEnum.LOG);
assertThat(liquibase).extracting("uiService").isEqualTo(UIServiceEnum.LOGGER);
}));
}

Expand Down Expand Up @@ -411,6 +413,16 @@ void overrideShowSummaryOutput() {
}));
}

@Test
void overrideUiService() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.liquibase.ui-service=console")
.run(assertLiquibase((liquibase) -> {
UIServiceEnum uiService = (UIServiceEnum) ReflectionTestUtils.getField(liquibase, "uiService");
assertThat(uiService).isEqualTo(UIServiceEnum.CONSOLE);
}));
}

@Test
@SuppressWarnings("unchecked")
void testOverrideParameters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand All @@ -21,10 +21,12 @@

import liquibase.UpdateSummaryEnum;
import liquibase.UpdateSummaryOutputEnum;
import liquibase.ui.UIServiceEnum;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.ShowSummary;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.ShowSummaryOutput;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.UIService;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -45,6 +47,11 @@ void valuesOfShowSummaryOutputMatchValuesOfUpdateSummaryOutputEnum() {
assertThat(namesOf(ShowSummaryOutput.values())).isEqualTo(namesOf(UpdateSummaryOutputEnum.values()));
}

@Test
void valuesOfUiServiceMatchValuesOfUiServiceEnum() {
assertThat(namesOf(UIService.values())).isEqualTo(namesOf(UIServiceEnum.values()));
}

private List<String> namesOf(Enum<?>[] input) {
return Stream.of(input).map(Enum::name).toList();
}
Expand Down