简体   繁体   中英

How start flyway manually in spring boot

How can I start flyway manually with Spring Boot? Because I have 2 dbs in my application, so after Springboot load the properties and before connect to DB, I need to run the flyway from my 2 dbs.

You can use flyway maven plugin to populate your databases.

You can either have two properties file for each database and execute flyway using mvn -Dflyway.configFile=myConfig.properties

Or

you can provide the db properties while executing maven like mvn -Dflyway.user=myUser -Dflyway.schemas=schema1,schema2 -Dflyway.placeholders.keyABC=valueXYZ

But please note that you have to execute flyway maven task twice. Each time for one database. Like,

$mvn -Dflyway.configFile=db1.properties compile migrate
$mvn -Dflyway.configFile=db2.properties compile migrate

Refer https://flywaydb.org/documentation/maven/ for more information.

If you are fine with this maven approach you don't need spring to do flyway migration.

If I understand you correctly, you don't want to start flyway manually, but run it on two databases. Here is how:

create two Datasources and mark one as @Primary, the other (should be a bean) as @FlywayDataSource. When flyway runs, it will automatically run on both data sources. see https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-execute-flyway-database-migrations-on-startup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM