Mee*_*ary 4 database-migration flyway spring-boot
我正在尝试使用Flyway 5.0.7设置两个不同的数据库,MySQL用于开发,H2用于测试。我已经在各自的文件中配置了两个数据库。
对于Development,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
Run Code Online (Sandbox Code Playgroud)
对于Testing,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
Run Code Online (Sandbox Code Playgroud)
以下是Flyway迁移文件的文件夹结构
在这种情况下迁飞是无法找到下迁移文件specific夹和应用时抛出错误V1.1__Insert_Records.sql的table not found。
如果将specific文件夹移入db/migration,相同版本的重复文件将出现错误。
有什么建议我应如何配置多个数据库的迁移文件以与Flyway一起使用?
我怀疑您可能在这里使用Spring Boot 2.x?如果是这样,flyway.locations则不再有效,将被忽略。
然后,Flyway将仅使用默认位置(db/migration),它将仅找到V1.1__Insert_Records.sql脚本而不找到V1__Create_table.sql脚本。
使用Spring Boot 2.x时,flyway.locations必须前缀spring.:
spring.flyway.locations=db/migration,db/specific/h2
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如果您{vendor}在该位置使用占位符,Spring Boot将从数据库驱动程序ID(h2,mysql,oracle等)的小写字母中找出该目录,这很好:
spring.flyway.locations=db/migration,db/specific/{vendor}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3898 次 |
| 最近记录: |