diff --git a/core/src/main/java/ch/ergon/adam/core/Adam.java b/core/src/main/java/ch/ergon/adam/core/Adam.java index 71aaefd..960b069 100644 --- a/core/src/main/java/ch/ergon/adam/core/Adam.java +++ b/core/src/main/java/ch/ergon/adam/core/Adam.java @@ -11,13 +11,16 @@ import ch.ergon.adam.core.prepost.MigrationScriptProvider; import ch.ergon.adam.core.prepost.MigrationStep; import ch.ergon.adam.core.prepost.MigrationStepExecutor; +import com.google.common.collect.Sets; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collection; import java.util.List; +import java.util.Set; import static ch.ergon.adam.core.prepost.MigrationStep.POSTMIGRATION_ALWAYS; import static ch.ergon.adam.core.prepost.MigrationStep.POSTMIGRATION_INIT; @@ -27,6 +30,7 @@ import static ch.ergon.adam.core.prepost.MigrationStep.PREMIGRATION_ONCE; import static ch.ergon.adam.core.prepost.db_schema_version.DbSchemaVersionSource.SCHEMA_VERSION_TABLE_NAME; import static com.google.common.collect.Lists.newArrayList; +import static com.google.common.collect.Sets.newHashSet; import static java.lang.ClassLoader.getSystemResourceAsStream; import static java.lang.String.format; @@ -49,6 +53,8 @@ public class Adam { private boolean allowUnknownDBVersion = false; private boolean allowNonForwardMigration = false; private boolean migrateSameVersion = false; + private Collection includes; + private Collection excludes; public static Adam usingGitRepo(String referenceSchemaUrl, String targetUrl, String targetVersion, File migrationScriptPath, File gitRepo) throws IOException { @@ -163,7 +169,7 @@ public void execute() throws IOException { MigrationStepExecutor executor = new MigrationStepExecutor(migrationScriptProvider, targetExecutor); executor.executeStep(PREMIGRATION_ALWAYS); executor.executeStep(PREMIGRATION_ONCE); - SchemaMigrator.migrate(referenceUrl, targetUrl); + SchemaMigrator.migrate(referenceUrl, targetUrl, getMigrationConfig()); executor.executeStep(POSTMIGRATION_ONCE); executor.executeStep(POSTMIGRATION_ALWAYS); } else { @@ -172,7 +178,7 @@ public void execute() throws IOException { if (isDbInit) { executor.executeStep(PREMIGRATION_INIT); } - SchemaMigrator.migrate(referenceUrl, targetUrl); + SchemaMigrator.migrate(referenceUrl, targetUrl, getMigrationConfig()); if (isDbInit) { executor.executeStep(POSTMIGRATION_INIT); } @@ -190,6 +196,17 @@ public void execute() throws IOException { } + private MigrationConfiguration getMigrationConfig() { + MigrationConfiguration migrationConfiguration = new MigrationConfiguration(); + Set excludeList = newHashSet(SCHEMA_VERSION_TABLE_NAME); + if (excludes != null) { + excludeList.addAll(excludes); + } + migrationConfiguration.setObjectNameExcludeList(excludeList); + migrationConfiguration.setObjectNameIncludeList(includes); + return migrationConfiguration; + } + private void logExecutionOrder(MigrationScriptProvider migrationScriptProvider) { logger.info("The following scripts will be executed in given order:"); logExecutionOrderForStep(migrationScriptProvider, PREMIGRATION_ALWAYS); @@ -261,4 +278,12 @@ public boolean isAllowNonForwardMigration() { public void setAllowNonForwardMigration(boolean allowNonForwardMigration) { this.allowNonForwardMigration = allowNonForwardMigration; } + + public void setIncludes(Collection includes) { + this.includes = includes; + } + + public void setExcludes(Collection excludes) { + this.excludes = excludes; + } } diff --git a/gradle-plugin/src/main/java/ch/ergon/adam/gradleplugin/tasks/MigrateDBTask.java b/gradle-plugin/src/main/java/ch/ergon/adam/gradleplugin/tasks/MigrateDBTask.java index 8e93b2a..ec1d7e0 100644 --- a/gradle-plugin/src/main/java/ch/ergon/adam/gradleplugin/tasks/MigrateDBTask.java +++ b/gradle-plugin/src/main/java/ch/ergon/adam/gradleplugin/tasks/MigrateDBTask.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.Collection; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Strings.isNullOrEmpty; @@ -25,6 +26,8 @@ public class MigrateDBTask extends DefaultTask { private boolean migrateSameVersion; private boolean allowNonForwardMigration; private AdamExtension extension; + private Collection excludes; + private Collection includes; public MigrateDBTask() { @@ -48,6 +51,8 @@ void migrateDb() throws IOException { adam.setAllowUnknownDBVersion(allowUnknownDBVersion); adam.setMigrateSameVersion(migrateSameVersion); adam.setAllowNonForwardMigration(allowNonForwardMigration); + adam.setIncludes(includes); + adam.setExcludes(excludes); adam.execute(); } @@ -114,4 +119,22 @@ public boolean getAllowNonForwardMigration() { public void setAllowNonForwardMigration(boolean allowNonForwardMigration) { this.allowNonForwardMigration = allowNonForwardMigration; } + + @Input + public Collection getExcludes() { + return excludes; + } + + public void setExcludes(Collection excludes) { + this.excludes = excludes; + } + + @Input + public Collection getIncludes() { + return includes; + } + + public void setIncludes(Collection includes) { + this.includes = includes; + } }