Skip to content

Commit

Permalink
Merge pull request #1049 from liquibase/DAT-4119
Browse files Browse the repository at this point in the history
Support --schemas flag both before and after the "snapshot" command
  • Loading branch information
nvoxland committed Apr 3, 2020
2 parents 5b19b18 + edc363a commit 7962511
Showing 1 changed file with 11 additions and 15 deletions.
Expand Up @@ -18,7 +18,6 @@
import liquibase.changelog.visitor.ChangeExecListener;
import liquibase.command.AbstractSelfConfiguratingCommand;
import liquibase.command.CommandFactory;
import liquibase.command.CommandResult;
import liquibase.command.LiquibaseCommand;
import liquibase.command.core.DropAllCommand;
import liquibase.command.core.ExecuteSqlCommand;
Expand Down Expand Up @@ -1424,11 +1423,7 @@ protected void doMigration() throws Exception {
SnapshotCommand snapshotCommand = (SnapshotCommand) CommandFactory.getInstance()
.getCommand(COMMANDS.SNAPSHOT);
snapshotCommand.setDatabase(database);
snapshotCommand.setSchemas(
getCommandParam(
OPTIONS.SCHEMAS, database.getDefaultSchema().getSchemaName()
)
);
snapshotCommand.setSchemas(getSchemaParams(database));
snapshotCommand.setSerializerFormat(getCommandParam(OPTIONS.SNAPSHOT_FORMAT, null));
Writer outputWriter = getOutputWriter();
String result = snapshotCommand.execute().print();
Expand All @@ -1453,11 +1448,7 @@ protected void doMigration() throws Exception {
.getCommand(COMMANDS.SNAPSHOT);
Database referenceDatabase = createReferenceDatabaseFromCommandParams(commandParams, fileOpener);
snapshotCommand.setDatabase(referenceDatabase);
snapshotCommand.setSchemas(
getCommandParam(
OPTIONS.SCHEMAS, referenceDatabase.getDefaultSchema().getSchemaName()
)
);
snapshotCommand.setSchemas(getSchemaParams(database));
snapshotCommand.setSerializerFormat(getCommandParam(OPTIONS.SNAPSHOT_FORMAT, null));
Writer outputWriter = getOutputWriter();
outputWriter.write(snapshotCommand.execute().print());
Expand Down Expand Up @@ -1598,10 +1589,7 @@ protected void doMigration() throws Exception {
DropAllCommand dropAllCommand = (DropAllCommand) CommandFactory.getInstance().getCommand
(COMMANDS.DROP_ALL);
dropAllCommand.setDatabase(liquibase.getDatabase());
dropAllCommand.setSchemas(getCommandParam(
OPTIONS.SCHEMAS, database.getDefaultSchema().getSchemaName())
);

dropAllCommand.setSchemas(getSchemaParams(database));
LogService.getLog(getClass()).info(LogType.USER_MESSAGE, dropAllCommand.execute().print());
return;
} else if (COMMANDS.STATUS.equalsIgnoreCase(command)) {
Expand Down Expand Up @@ -1784,6 +1772,14 @@ protected void doMigration() throws Exception {
}
}

private String getSchemaParams(Database database) throws CommandLineParsingException {
String schemaParams = getCommandParam(OPTIONS.SCHEMAS, schemas);
if (schemaParams == null || schemaParams.isEmpty()) {
return database.getDefaultSchema().getSchemaName();
}
return schemaParams;
}

private LiquibaseCommand createLiquibaseCommand(Database database, Liquibase liquibase, String commandName, Map<String, Object> argsMap)
throws CommandLineParsingException, LiquibaseException {
LiquibaseCommand liquibaseCommand = CommandFactory.getInstance().getCommand(commandName);
Expand Down

0 comments on commit 7962511

Please sign in to comment.