springcloud中使用flyway做數據遷移時要注意的問題

  • pom中引用flyway的core包
<dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>5.2.4</version>
        </dependency>
  • 建立sql存放目錄時要注意命名,如:db.migration,要先建立db目錄再建立migration目錄,由於在application.yml通常配置的是兩級目錄
flyway:
    baseline-on-migrate: true
    locations: classpath:/db/migration
  • 若是每一個微服務的resource中都有本身的db/migration,默認狀況下會報

nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected applied migration not resolved locallysql

這是由於經過flyway_schema_history表對本地sql文件進行連續性驗證的結果,關閉驗證便可。api

flyway:
    baseline-on-migrate: true
    validate-on-migrate: false
    locations: classpath:/db/migration
相關文章
相關標籤/搜索