Skip to content
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

Enable snapshotByDefault for Data if output directory specified DAT-4129 #1033

Merged
merged 3 commits into from Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,6 +22,7 @@ public class GlobalConfiguration extends AbstractConfigurationContainer {
public static final String ALWAYS_OVERRIDE_STORED_LOGIC_SCHEMA = "alwaysOverrideStoredLogicSchema";
public static final String GENERATED_CHANGESET_IDS_INCLUDE_DESCRIPTION = "generatedChangeSetIdsContainsDescription";
public static final String INCLUDE_CATALOG_IN_SPECIFICATION = "includeCatalogInSpecification";
public static final String SHOULD_SNAPSHOT_DATA = "shouldSnapshotData";

public GlobalConfiguration() {
super("liquibase");
Expand Down Expand Up @@ -95,6 +96,10 @@ public GlobalConfiguration() {
getContainer().addProperty(INCLUDE_CATALOG_IN_SPECIFICATION, Boolean.class)
.setDescription("Should Liquibase include the catalog name when determining equality?")
.setDefaultValue(false);

getContainer().addProperty(SHOULD_SNAPSHOT_DATA, Boolean.class)
.setDescription("Should Liquibase snapshot data by default?")
.setDefaultValue(false);
}

/**
Expand Down Expand Up @@ -169,6 +174,20 @@ public GlobalConfiguration setLiquibaseTablespaceName(String name) {
return this;
}

/**
*
* Should Liquibase snapshot data for table by default
*
*/
public boolean getShouldSnapshotData() {
return getContainer().getValue(SHOULD_SNAPSHOT_DATA, Boolean.class);
}

public GlobalConfiguration setShouldSnapshotData(boolean shouldSnapshotData) {
getContainer().setValue(SHOULD_SNAPSHOT_DATA, shouldSnapshotData);
return this;
}

/**
* Name of the catalog to use for liquibase database objects
*/
Expand Down
Expand Up @@ -1341,6 +1341,12 @@ protected void doMigration() throws Exception {
OPTIONS.EXCLUDE_OBJECTS, OPTIONS.INCLUDE_OBJECTS));
}

//
// Set the global configuration option based on presence of the dataOutputDirectory
//
boolean b = dataOutputDirectory != null;
LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).setShouldSnapshotData(b);

ObjectChangeFilter objectChangeFilter = null;
CompareControl.ComputedSchemas computedSchemas = CompareControl.computeSchemas(
schemas,
Expand Down
@@ -1,13 +1,15 @@
package liquibase.structure.core;

import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.structure.AbstractDatabaseObject;
import liquibase.structure.DatabaseObject;

public class Data extends AbstractDatabaseObject {

@Override
public boolean snapshotByDefault() {
return false;
return LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getShouldSnapshotData();
}

public Table getTable() {
Expand Down
@@ -1,6 +1,8 @@
package org.liquibase.maven.plugins;

import liquibase.Liquibase;
import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.diff.output.DiffOutputControl;
import liquibase.diff.output.StandardObjectChangeFilter;
Expand Down Expand Up @@ -111,6 +113,12 @@ protected void performLiquibaseTask(Liquibase liquibase)
diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.INCLUDE, diffIncludeObjects));
}

//
// Set the global configuration option based on presence of the dataOutputDirectory
//
boolean b = dataDir != null;
LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).setShouldSnapshotData(b);

CommandLineUtils.doGenerateChangeLog(outputChangeLogFile, database, defaultCatalogName, defaultSchemaName, StringUtils.trimToNull(diffTypes),
StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataDir), diffOutputControl);
getLog().info("Output written to Change Log file, " + outputChangeLogFile);
Expand Down