All Downloads are FREE. Search and download functionalities are using the official Maven repository.

in.cleartax.dropwizard.sharding.migrations.DbCalculateChecksumCommand Maven / Gradle / Ivy

There is a newer version: 0.2.198
Show newest version
package in.cleartax.dropwizard.sharding.migrations;

import com.google.common.annotations.VisibleForTesting;
import io.dropwizard.Configuration;
import liquibase.Liquibase;
import liquibase.change.CheckSum;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Consumer;

public class DbCalculateChecksumCommand extends AbstractLiquibaseCommand {
    private static final Logger LOGGER = LoggerFactory.getLogger("liquibase");

    private Consumer checkSumConsumer = (checkSum) -> LOGGER.info("checksum = {}", checkSum);

    public DbCalculateChecksumCommand(MultiTenantDatabaseConfiguration strategy, Class configurationClass, String migrationsFileName) {
        super("calculate-checksum", "Calculates and prints a checksum for a change set", strategy,
                configurationClass, migrationsFileName);
    }

    @VisibleForTesting
    void setCheckSumConsumer(Consumer checkSumConsumer) {
        this.checkSumConsumer = checkSumConsumer;
    }

    @Override
    public void configure(Subparser subparser) {
        super.configure(subparser);

        subparser.addArgument("id").nargs(1).help("change set id");
        subparser.addArgument("author").nargs(1).help("author name");
    }

    @Override
    public void run(Namespace namespace,
                    Liquibase liquibase) throws Exception {
        final CheckSum checkSum = liquibase.calculateCheckSum("migrations.xml",
                namespace.getList("id").get(0),
                namespace.getList("author").get(0));
        checkSumConsumer.accept(checkSum);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy