我正在尝试使用Flyway 5.0.7设置两个不同的数据库,MySQL用于开发,H2用于测试。我已经在各自的文件中配置了这两个数据库。
对于开发, src / main / resource / application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/moment
spring.datasource.username=root
spring.datasource.password=root
flyway.locations=db/migration,db/specific/mysql
对于测试, src / test / resource / application.properties
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa
flyway.locations=db/migration,db/specific/h2
下面是Flyway迁移文件的文件夹结构
在这种情况下,Flyway无法在specific
文件夹下找到迁移文件,并且在为V1.1__Insert_Records.sql
应用table not found
时抛出错误。
如果将specific
文件夹移到db/migration
内,则相同版本的重复文件会出错。
任何建议如何配置多个数据库的迁移文件以与Flyway一起使用?
答案 0 :(得分:2)
我怀疑您可能在这里使用Spring Boot 2.x?如果是这样,flyway.locations
不再有效,将被忽略。
然后,Flyway将仅使用默认位置(db/migration
),它将仅找到V1.1__Insert_Records.sql
脚本,而找不到V1__Create_table.sql
脚本。
使用Spring Boot 2.x,flyway.locations
must be prefixed with spring.
:
spring.flyway.locations=db/migration,db/specific/h2
如果在位置使用{vendor}
占位符,请从数据库驱动程序ID(h2,mysql,oracle等)的小写字母中使用Spring Boot will work out the directory,这很不错:>
spring.flyway.locations=db/migration,db/specific/{vendor}