-
-
Save mihkell/ac0ea5c47655ec29066f34fafb180bf7 to your computer and use it in GitHub Desktop.
Flyway example for Stackoverflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class FlywayConfiguration { | |
@Bean(initMethod = "migrate") | |
@FlywayDataSource | |
public Flyway firstFlyway(DataSource dataSource) { | |
return new Flyway( | |
new FluentConfiguration() | |
.locations("db/first-migration") | |
.schemas("first") | |
.outOfOrder(true) | |
.dataSource(dataSource) | |
); | |
} | |
@Bean(initMethod = "migrate") | |
@FlywayDataSource | |
public Flyway secondFlyway(@Qualifier("secondDataSource") DataSource dataSource) { | |
return new Flyway( | |
new FluentConfiguration() | |
.dataSource(dataSource) | |
.schemas("second") | |
.outOfOrder(true) | |
.locations("db/second-migration") | |
); | |
} | |
} | |
@Configuration | |
public class FlywayTestConfig { | |
@Autowired | |
@Qualifier("secondFlyway") | |
private Flyway secondFlyway; | |
@Autowired | |
@Qualifier("firstFlyway") | |
private Flyway firstFlyway; | |
@PostConstruct | |
public void cleanBeforeMigrate() { | |
secondFlyway.clean(); | |
secondFlyway.migrate(); | |
firstFlyway.clean(); | |
firstFlyway.migrate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment