use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.
the class FlywayCallbackSmallTest method cleanTest.
@Test
public void cleanTest() {
Properties properties = createProperties("clean");
FlywayCallbackImpl callbackImpl = new FlywayCallbackImpl();
FlywayCallback[] callbacks = new FlywayCallback[] { callbackImpl };
final Flyway flyway = new Flyway();
flyway.configure(properties);
flyway.setCallbacks(callbacks);
assertNotNull(flyway.getDataSource());
assertFalse(callbackImpl.isBeforeClean());
assertFalse(callbackImpl.isAfterClean());
flyway.clean();
assertTrue(callbackImpl.isBeforeClean());
assertTrue(callbackImpl.isAfterClean());
//make sure no other lifecycle events were fired
assertFalse(callbackImpl.isAfterEachMigrate());
assertFalse(callbackImpl.isAfterInfo());
assertFalse(callbackImpl.isAfterBaseline());
assertFalse(callbackImpl.isAfterMigrate());
assertFalse(callbackImpl.isAfterRepair());
assertFalse(callbackImpl.isAfterValidate());
assertFalse(callbackImpl.isBeforeEachMigrate());
assertFalse(callbackImpl.isBeforeInfo());
assertFalse(callbackImpl.isBeforeBaseline());
assertFalse(callbackImpl.isBeforeMigrate());
assertFalse(callbackImpl.isBeforeRepair());
assertFalse(callbackImpl.isBeforeValidate());
}
use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.
the class FlywaySmallTest method configure.
@Test
public void configure() {
Properties properties = new Properties();
properties.setProperty("flyway.user", "sa");
properties.setProperty("flyway.password", "");
properties.setProperty("flyway.url", "jdbc:h2:mem:flyway_test;DB_CLOSE_DELAY=-1");
properties.setProperty("flyway.driver", "org.h2.Driver");
final Flyway flyway = new Flyway();
flyway.configure(properties);
assertNotNull(flyway.getDataSource());
flyway.execute(new Flyway.Command<Void>() {
public Void execute(Connection connectionMetaDataTable, MigrationResolver migrationResolver, MetaDataTable metaDataTable, DbSupport dbSupport, Schema[] schemas, FlywayCallback[] flywayCallbacks) {
assertEquals("PUBLIC", flyway.getSchemas()[0]);
return null;
}
});
}
use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.
the class DbMigrate method doMigrate.
private void doMigrate(MigrationInfoImpl migration, MigrationExecutor migrationExecutor, String migrationText) throws SQLException {
dbSupportUserObjects.changeCurrentSchemaTo(schema);
for (final FlywayCallback callback : configuration.getCallbacks()) {
callback.beforeEachMigrate(connectionUserObjects, migration);
}
migrationExecutor.execute(connectionUserObjects);
LOG.debug("Successfully completed migration of " + migrationText);
for (final FlywayCallback callback : configuration.getCallbacks()) {
callback.afterEachMigrate(connectionUserObjects, migration);
}
}
use of org.flywaydb.core.api.callback.FlywayCallback in project flyway by flyway.
the class Flyway method info.
/**
* <p>Retrieves the complete information about all the migrations including applied, pending and current migrations with
* details and status.</p>
* <img src="https://flywaydb.org/assets/balsamiq/command-info.png" alt="info">
*
* @return All migrations sorted by version, oldest first.
* @throws FlywayException when the info retrieval failed.
*/
public MigrationInfoService info() {
return execute(new Command<MigrationInfoService>() {
public MigrationInfoService execute(final Connection connectionMetaDataTable, MigrationResolver migrationResolver, MetaDataTable metaDataTable, final DbSupport dbSupport, final Schema[] schemas, FlywayCallback[] flywayCallbacks) {
try {
for (final FlywayCallback callback : flywayCallbacks) {
new TransactionTemplate(connectionMetaDataTable).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schemas[0]);
callback.beforeInfo(connectionMetaDataTable);
return null;
}
});
}
MigrationInfoServiceImpl migrationInfoService = new MigrationInfoServiceImpl(migrationResolver, metaDataTable, target, outOfOrder, true, true, true);
migrationInfoService.refresh();
for (final FlywayCallback callback : flywayCallbacks) {
new TransactionTemplate(connectionMetaDataTable).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schemas[0]);
callback.afterInfo(connectionMetaDataTable);
return null;
}
});
}
return migrationInfoService;
} finally {
dbSupport.restoreCurrentSchema();
}
}
});
}
use of org.flywaydb.core.api.callback.FlywayCallback in project spring-boot by spring-projects.
the class FlywayAutoConfigurationTests method callbacksAreConfiguredAndOrdered.
@Test
public void callbacksAreConfiguredAndOrdered() throws Exception {
registerAndRefresh(EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, CallbackConfiguration.class);
assertThat(this.context.getBeansOfType(Flyway.class)).hasSize(1);
Flyway flyway = this.context.getBean(Flyway.class);
FlywayCallback callbackOne = this.context.getBean("callbackOne", FlywayCallback.class);
FlywayCallback callbackTwo = this.context.getBean("callbackTwo", FlywayCallback.class);
assertThat(flyway.getCallbacks()).containsExactly(callbackTwo, callbackOne);
InOrder orderedCallbacks = inOrder(callbackOne, callbackTwo);
orderedCallbacks.verify(callbackTwo).beforeMigrate(any(Connection.class));
orderedCallbacks.verify(callbackOne).beforeMigrate(any(Connection.class));
}
Aggregations