BAEL-3498: Conditionally Disable Flyway
This commit is contained in:
parent
dd9a7593c1
commit
e57ae9f271
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.flywaycallbacks;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.flywaydb.core.Flyway;
|
||||||
|
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class EmptyMigrationStrategyConfig {
|
||||||
|
|
||||||
|
private Log log = LogFactory.getLog("EmptyMigrationStrategy");
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FlywayMigrationStrategy flywayMigrationStrategy() {
|
||||||
|
return new FlywayMigrationStrategy() {
|
||||||
|
@Override
|
||||||
|
public void migrate(Flyway flyway) {
|
||||||
|
log.info("Skipping Flyway migration!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
#flyway.enabled=false
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.flywaycallbacks;
|
||||||
|
|
||||||
|
import org.flywaydb.core.Flyway;
|
||||||
|
import org.flywaydb.core.api.MigrationInfo;
|
||||||
|
import org.flywaydb.core.api.MigrationState;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class ManualFlywayMigrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Flyway flyway;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void skipAutomaticAndTriggerManualFlywayMigration() {
|
||||||
|
|
||||||
|
assertAllMigrationsAre(MigrationState.PENDING);
|
||||||
|
|
||||||
|
flyway.migrate();
|
||||||
|
|
||||||
|
assertAllMigrationsAre(MigrationState.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertAllMigrationsAre(MigrationState expectedState) {
|
||||||
|
for (MigrationInfo migrationInfo : flyway.info().all()) {
|
||||||
|
assertThat(migrationInfo.getState()).isEqualTo(expectedState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user