Flyway - 找不到迁移位置
Flyway - Cannot find migrations location in
我似乎无法让 flyway 知道在哪里寻找我的迁移。
我的文件结构是默认从 spring initializr 生成的。
我的迁移位于:./demo/src/main/kotlin/db/migration
我的迁移基于 java
我的 application.properties 文件如下所示:
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://${JDBC_DATABASE_URL}/jpaTestDatabase
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:demo/src/main/kotlin/db/migration
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.session.store-type=none
我尝试了几个类路径:
/demo/src/main/kotlin/db/migration
demo/src/main/kotlin/db/migration
/src/main/kotlin/db/migration
src/main/kotlin/db/migration
None 以上似乎有效。
如何让 flyway 知道迁移的位置?
默认情况下,Flyway 将在 db/migration 下的类路径上查找迁移,这在 Maven 项目中意味着 src/main/resources/db/migration.
确保你有这样的目录。
参考flyway-db-migration-folder
就我而言,我收到该错误消息是因为我在 IDE 中通过复制粘贴创建了文件夹(而不是像通常那样手动创建)。
我实际上有(没有用):
src/main/resources/db.migration/
而不是正确的(有效):
src/main/resources/db/migration/
db.migration
版本明显不行,但是在IDE上就很难看出来了。
您必须将 flyway.locations 行与
合并或取消注释
flyway.localtions=filesystem:.
进入flyway.conf配置文件。
我有一个不同的问题,我的迁移文件名是 V1_Base_version.sql
而不是 V1__Base_version.sql
。 Flyway 需要在名称前缀中使用双下划线 __
。
在我的例子中,诀窍是:一旦 Flyway 成功 运行 更新脚本,它就会创建 table flyway_schema_history,记录下我已经运行创建脚本成功一次。
我在实施中来回播放,改变
spring.jpa.hibernate.ddl-auto 到 validate 然后 create-drop,然后返回。
因此,当我第二次尝试 运行 脚本时,该脚本被拒绝了,但由于最初创建的 table(在我的例子中称为 'bike')在应用程序时被删除上次在 spring.jpa.hibernate.ddl-auto=create-drop 模式下 运行 时关闭,我得到
SchemaManagementException: Schema-validation: missing table [bike]
异常。
解决办法是:丢掉flyway_schema_historytable或者把前面运行对应的记录去掉再roll!
在我的例子中,我在迁移名称中有 -
(短划线字符),例如 V20220508-1900__init.sql
。删除 -
解决了问题
我似乎无法让 flyway 知道在哪里寻找我的迁移。 我的文件结构是默认从 spring initializr 生成的。 我的迁移位于:./demo/src/main/kotlin/db/migration 我的迁移基于 java
我的 application.properties 文件如下所示:
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://${JDBC_DATABASE_URL}/jpaTestDatabase
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:demo/src/main/kotlin/db/migration
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.session.store-type=none
我尝试了几个类路径:
/demo/src/main/kotlin/db/migration
demo/src/main/kotlin/db/migration
/src/main/kotlin/db/migration
src/main/kotlin/db/migration
None 以上似乎有效。
如何让 flyway 知道迁移的位置?
默认情况下,Flyway 将在 db/migration 下的类路径上查找迁移,这在 Maven 项目中意味着 src/main/resources/db/migration.
确保你有这样的目录。
参考flyway-db-migration-folder
就我而言,我收到该错误消息是因为我在 IDE 中通过复制粘贴创建了文件夹(而不是像通常那样手动创建)。
我实际上有(没有用):
src/main/resources/db.migration/
而不是正确的(有效):
src/main/resources/db/migration/
db.migration
版本明显不行,但是在IDE上就很难看出来了。
您必须将 flyway.locations 行与
合并或取消注释flyway.localtions=filesystem:.
进入flyway.conf配置文件。
我有一个不同的问题,我的迁移文件名是 V1_Base_version.sql
而不是 V1__Base_version.sql
。 Flyway 需要在名称前缀中使用双下划线 __
。
在我的例子中,诀窍是:一旦 Flyway 成功 运行 更新脚本,它就会创建 table flyway_schema_history,记录下我已经运行创建脚本成功一次。
我在实施中来回播放,改变 spring.jpa.hibernate.ddl-auto 到 validate 然后 create-drop,然后返回。
因此,当我第二次尝试 运行 脚本时,该脚本被拒绝了,但由于最初创建的 table(在我的例子中称为 'bike')在应用程序时被删除上次在 spring.jpa.hibernate.ddl-auto=create-drop 模式下 运行 时关闭,我得到
SchemaManagementException: Schema-validation: missing table [bike]
异常。
解决办法是:丢掉flyway_schema_historytable或者把前面运行对应的记录去掉再roll!
在我的例子中,我在迁移名称中有 -
(短划线字符),例如 V20220508-1900__init.sql
。删除 -
解决了问题