Skip to content

Commit

Permalink
Merge pull request #1033 from liquibase/DAT-4129
Browse files Browse the repository at this point in the history
Enable snapshotByDefault for Data if output directory specified DAT-4129
  • Loading branch information
nvoxland committed Apr 3, 2020
2 parents 99db835 + 118e5a8 commit 9cb708c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
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

0 comments on commit 9cb708c

Please sign in to comment.