Skip to content

Commit

Permalink
Add configuration option for liquibase.allowDuplicatedChangesetIdenti…
Browse files Browse the repository at this point in the history
…fiers

Closes: #40493
  • Loading branch information
geoand committed May 14, 2024
1 parent 2c42581 commit f52e66b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.agroal.api.AgroalDataSource;
import io.quarkus.liquibase.runtime.LiquibaseConfig;
import io.quarkus.runtime.ResettableSystemProperties;
import io.quarkus.runtime.util.StringUtil;
import liquibase.Contexts;
import liquibase.LabelExpression;
Expand Down Expand Up @@ -150,4 +151,12 @@ public Contexts createContexts() {
public String getDataSourceName() {
return dataSourceName;
}

public ResettableSystemProperties createResettableSystemProperties() {
if (config.allowDuplicatedChangesetIdentifiers.isEmpty()) {
return ResettableSystemProperties.empty();
}
return ResettableSystemProperties.of("liquibase.allowDuplicatedChangesetIdentifiers",
config.allowDuplicatedChangesetIdentifiers.get().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ public class LiquibaseConfig {
*/
public Optional<String> password = Optional.empty();

/**
* Allows duplicated changeset identifiers without failing Liquibase execution.
*/
public Optional<Boolean> allowDuplicatedChangesetIdentifiers;

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public LiquibaseFactory createLiquibaseFactory(DataSource dataSource, String dat
config.migrateAtStart = liquibaseRuntimeConfig.migrateAtStart;
config.cleanAtStart = liquibaseRuntimeConfig.cleanAtStart;
config.validateOnMigrate = liquibaseRuntimeConfig.validateOnMigrate;
config.allowDuplicatedChangesetIdentifiers = liquibaseRuntimeConfig.allowDuplicatedChangesetIdentifiers;
return new LiquibaseFactory(config, dataSource, dataSourceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,10 @@ public static final LiquibaseDataSourceRuntimeConfig defaultConfig() {
@ConfigItem
public Optional<String> liquibaseTablespaceName = Optional.empty();

/**
* Allows duplicated changeset identifiers without failing Liquibase execution.
*/
@ConfigItem
public Optional<Boolean> allowDuplicatedChangesetIdentifiers = Optional.empty();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.datasource.common.runtime.DataSourceUtil;
import io.quarkus.liquibase.LiquibaseFactory;
import io.quarkus.runtime.ResettableSystemProperties;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import liquibase.Liquibase;
Expand Down Expand Up @@ -66,7 +67,9 @@ public void doStartActions(String dataSourceName) {
if (!config.cleanAtStart && !config.migrateAtStart) {
return;
}
try (Liquibase liquibase = liquibaseFactory.createLiquibase()) {
try (Liquibase liquibase = liquibaseFactory.createLiquibase();
ResettableSystemProperties resettableSystemProperties = liquibaseFactory
.createResettableSystemProperties()) {
if (config.cleanAtStart) {
liquibase.dropAll();
}
Expand Down

0 comments on commit f52e66b

Please sign in to comment.