io.dropwizard.flyway.FlywayFactory Java Examples

The following examples show how to use io.dropwizard.flyway.FlywayFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DbMigrateCommand.java    From dropwizard-flyway with Apache License 2.0 6 votes vote down vote up
@Override
protected void setAdditionalOptions(FlywayFactory flywayFactory, Namespace namespace) {
    final Boolean outOfOrder = namespace.getBoolean(OUT_OF_ORDER);
    final Boolean validateOnMigrate = namespace.getBoolean(VALIDATE_ON_MIGRATE);
    final Boolean cleanOnValidationError = namespace.getBoolean(CLEAN_ON_VALIDATION_ERROR);
    final Boolean baselineOnMigrate = namespace.getBoolean(INIT_ON_MIGRATE);

    if (outOfOrder != null) {
        flywayFactory.setOutOfOrder(outOfOrder);
    }

    if (validateOnMigrate != null) {
        flywayFactory.setValidateOnMigrate(validateOnMigrate);
    }

    if (cleanOnValidationError != null) {
        flywayFactory.setCleanOnValidationError(cleanOnValidationError);
    }

    if (baselineOnMigrate != null) {
        flywayFactory.setBaselineOnMigrate(baselineOnMigrate);
    }
}
 
Example #2
Source File: AbstractFlywayCommand.java    From dropwizard-flyway with Apache License 2.0 6 votes vote down vote up
@Override
protected void run(final Bootstrap<T> bootstrap, final Namespace namespace, final T configuration) throws Exception {
    final PooledDataSourceFactory datasourceFactory = databaseConfiguration.getDataSourceFactory(configuration);
    final FlywayFactory flywayFactory = flywayConfiguration.getFlywayFactory(configuration);

    // Give subclasses an option to set additional config flags for flyway.
    setAdditionalOptions(flywayFactory, namespace);
    
    final Flyway flyway = flywayFactory.build(datasourceFactory.build(bootstrap.getMetricRegistry(), "Flyway"));

    try {
        run(namespace, flyway);
    } catch (FlywayException e) {
        LOG.error("Error while running database command", e);
        throw e;
    }
}
 
Example #3
Source File: AbstractCommandTest.java    From dropwizard-flyway with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    // Setup necessary mock
    final JarLocation location = mock(JarLocation.class);
    when(location.getVersion()).thenReturn(Optional.of("1.0.0"));

    final DatabaseConfiguration dbConfiguration = mock(DatabaseConfiguration.class);
    when(dbConfiguration.getDataSourceFactory(any())).thenReturn(mock(PooledDataSourceFactory.class));

    final FlywayConfiguration flywayConfiguration = mock(FlywayConfiguration.class);
    mockFlywayFactory = mock(FlywayFactory.class);
    when(flywayConfiguration.getFlywayFactory(any())).thenReturn(mockFlywayFactory);

    mockFlyway = mock(Flyway.class);
    when(mockFlywayFactory.build(any())).thenReturn(mockFlyway);

    // Add commands you want to test
    final Bootstrap<TestConfiguration> bootstrap = new Bootstrap<>(new TestApplication());
    bootstrap.addCommand(new DbCommand<TestConfiguration>("db", dbConfiguration, flywayConfiguration, TestConfiguration.class));

    // Build what'll run the command and interpret arguments
    cli = new Cli(location, bootstrap, System.out, System.err);
}
 
Example #4
Source File: DbValidateCommand.java    From dropwizard-flyway with Apache License 2.0 5 votes vote down vote up
@Override
protected void setAdditionalOptions(FlywayFactory flywayFactory, Namespace namespace) {
    final Boolean outOfOrder = namespace.getBoolean(OUT_OF_ORDER);
    final Boolean cleanOnValidationError = namespace.getBoolean(CLEAN_ON_VALIDATION_ERROR);
    
    if (outOfOrder != null) {
        flywayFactory.setOutOfOrder(outOfOrder);
    }

    if (cleanOnValidationError != null) {
        flywayFactory.setCleanOnValidationError(cleanOnValidationError);
    }

}
 
Example #5
Source File: NoOptionsFlywayCommand.java    From dropwizard-flyway with Apache License 2.0 4 votes vote down vote up
@Override
protected void setAdditionalOptions(FlywayFactory flywayFactory, Namespace namespace) {
    // Empty on purpose
}
 
Example #6
Source File: DbCommand.java    From dropwizard-flyway with Apache License 2.0 4 votes vote down vote up
@Override
protected void setAdditionalOptions(FlywayFactory flywayFactory, Namespace namespace) {
    subCommands.get(namespace.getString(COMMAND_NAME_ATTR)).setAdditionalOptions(flywayFactory, namespace);
}
 
Example #7
Source File: ExampleConfig.java    From droptools with Apache License 2.0 4 votes vote down vote up
public FlywayFactory flyway() {
    return flyway;
}
 
Example #8
Source File: AbstractFlywayCommand.java    From dropwizard-flyway with Apache License 2.0 votes vote down vote up
protected abstract void setAdditionalOptions(FlywayFactory flywayFactory, Namespace namespace);