Search in sources :

Example 6 with Flyway

use of org.flywaydb.core.Flyway in project keywhiz by square.

the class KeywhizService method validateDatabase.

private void validateDatabase(KeywhizConfig config) {
    logger.debug("Validating database state");
    DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "flyway-validation-datasource");
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations(config.getMigrationsDir());
    flyway.validate();
}
Also used : Flyway(org.flywaydb.core.Flyway) MetricRegistry(com.codahale.metrics.MetricRegistry) DataSource(javax.sql.DataSource)

Example 7 with Flyway

use of org.flywaydb.core.Flyway in project keywhiz by square.

the class MigrateCommand method run.

@Override
protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception {
    DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "migration-datasource");
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations(config.getMigrationsDir());
    flyway.migrate();
}
Also used : Flyway(org.flywaydb.core.Flyway) MetricRegistry(com.codahale.metrics.MetricRegistry) DataSource(javax.sql.DataSource)

Example 8 with Flyway

use of org.flywaydb.core.Flyway in project keywhiz by square.

the class PreviewMigrateCommand method run.

@Override
protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception {
    DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "migration-preview-datasource");
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations(config.getMigrationsDir());
    MigrationInfoService info = flyway.info();
    MigrationInfo current = info.current();
    if (current == null) {
        logger.info("No migrations have been run yet.");
    } else {
        logger.info("Currently applied migration:");
        logger.info("* {} - {}", current.getVersion(), current.getDescription());
    }
    if (info.pending().length > 0) {
        logger.info("Pending migrations:");
        for (MigrationInfo migration : info.pending()) {
            logger.info("* {} - {}", migration.getVersion(), migration.getDescription());
        }
    } else {
        logger.info("No pending migrations");
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService) MetricRegistry(com.codahale.metrics.MetricRegistry) DataSource(javax.sql.DataSource)

Example 9 with Flyway

use of org.flywaydb.core.Flyway in project flyway by flyway.

the class H2CaseSensitiveMigrationMediumTest method migrate.

@Test
public void migrate() {
    Flyway flyway = new Flyway();
    flyway.setDataSource("jdbc:h2:mem:flyway_db_case_sensitive;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=FALSE", "sa", "");
    flyway.setLocations("migration/sql");
    flyway.migrate();
    flyway.clean();
}
Also used : Flyway(org.flywaydb.core.Flyway) Test(org.junit.Test)

Example 10 with Flyway

use of org.flywaydb.core.Flyway in project flyway by flyway.

the class H2MigrationMediumTest method mysqlMode.

@Test
public void mysqlMode() throws Exception {
    Flyway flyway = new Flyway();
    flyway.setDataSource("jdbc:h2:mem:mysql_db;MODE=MySQL;DB_CLOSE_DELAY=-1", "sa", "");
    flyway.setSchemas("mysql_schema");
    flyway.baseline();
}
Also used : Flyway(org.flywaydb.core.Flyway) Test(org.junit.Test)

Aggregations

Flyway (org.flywaydb.core.Flyway)44 Test (org.junit.Test)26 Connection (java.sql.Connection)7 DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)6 File (java.io.File)5 SQLException (java.sql.SQLException)5 Properties (java.util.Properties)5 DataSource (javax.sql.DataSource)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 Statement (java.sql.Statement)4 FlywayException (org.flywaydb.core.api.FlywayException)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MavenProject (org.apache.maven.project.MavenProject)2 MigrationInfo (org.flywaydb.core.api.MigrationInfo)2 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1