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

Support --schemas flag both before and after the "snapshot" command #1049

Merged
merged 3 commits into from Apr 3, 2020
Merged
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 @@ -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 @@ -1418,11 +1417,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 @@ -1447,11 +1442,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 @@ -1592,10 +1583,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 @@ -1778,6 +1766,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