com.github.joschi.dropwizard.flyway.DbCommand Maven / Gradle / Ivy
package com.github.joschi.dropwizard.flyway;
import io.dropwizard.Configuration;
import io.dropwizard.db.DatabaseConfiguration;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.flywaydb.core.Flyway;
import java.util.SortedMap;
import java.util.TreeMap;
public class DbCommand extends AbstractFlywayCommand {
private static final String COMMAND_NAME_ATTR = "subCommand";
private final SortedMap> subCommands = new TreeMap<>();
public DbCommand(final DatabaseConfiguration configuration, final Class configurationClass) {
super("db", "Run database migration tasks", configuration, configurationClass);
addSubCommand(new DbMigrateCommand<>(configuration, configurationClass));
addSubCommand(new DbCleanCommand<>(configuration, configurationClass));
addSubCommand(new DbInitCommand<>(configuration, configurationClass));
addSubCommand(new DbValidateCommand<>(configuration, configurationClass));
addSubCommand(new DbInfoCommand<>(configuration, configurationClass));
addSubCommand(new DbRepairCommand<>(configuration, configurationClass));
}
private void addSubCommand(final AbstractFlywayCommand subCommand) {
subCommands.put(subCommand.getName(), subCommand);
}
@Override
public void configure(final Subparser subparser) {
for (AbstractFlywayCommand subCommand : subCommands.values()) {
final Subparser cmdParser = subparser.addSubparsers()
.addParser(subCommand.getName())
.setDefault(COMMAND_NAME_ATTR, subCommand.getName())
.description(subCommand.getDescription());
subCommand.configure(cmdParser);
}
}
@Override
public void run(final Namespace namespace, final Flyway flyway) throws Exception {
subCommands.get(namespace.getString(COMMAND_NAME_ATTR)).run(namespace, flyway);
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy