为啥 flyway 会忽略我的 SQL 迁移文件?
Posted
技术标签:
【中文标题】为啥 flyway 会忽略我的 SQL 迁移文件?【英文标题】:Why is flyway ignoring my SQL migration files?为什么 flyway 会忽略我的 SQL 迁移文件? 【发布时间】:2016-04-28 19:00:10 【问题描述】:我们在我们的 java 中使用 flyway,基于 gradle spring 的 MVC 应用程序。我将我的 SQL 文件保存在 src/main/resources/db/migration 文件夹中。
下面是我的 flyway gradle 配置文件。
apply plugin: "org.flywaydb.flyway"
flyway
driver = 'com.mysql.jdbc.Driver'
url = "jdbc:mysql://localhost:3306/java_app_test"
user = 'root'
password = ''
schemas = ['java_app_test']
outOfOrder = true
locations = [
//"filesystem:$project.projectDir/dbScripts/migrations"
"classpath:db/migration"
]
当我运行 gradle flywayBaseline 时,我得到如下输出。
13:57:06.291 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/20160121042238016__initial.sql
13:57:06.292 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/20160122081606826__initial.sql
13:57:06.311 [DEBUG] [org.flywaydb.core.internal.command.DbSchemas] Schema `java_app_test` already exists. Skipping schema creation.
13:57:06.358 [DEBUG] [org.flywaydb.core.internal.metadatatable.MetaDataTableImpl] MetaData table `java_app_test`.`schema_version` successfully updated to reflect changes
13:57:06.422 [INFO] [org.flywaydb.core.internal.command.DbBaseline] Schema baselined with version: 1
它找到了我的 sql 文件,但它没有执行它。
当我运行 flywayMigrate 时,我得到以下输出
14:12:41.285 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/20160121042238016__initial.sql (filename: 20160121042238016__initial.sql)
14:12:41.285 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/20160122081606826__initial.sql (filename: 20160122081606826__initial.sql)
14:12:41.314 [INFO] [org.flywaydb.core.internal.command.DbValidate] Validated 1 migration (execution time 00:00.047s)
14:12:41.335 [DEBUG] [org.flywaydb.core.internal.command.DbSchemas] Schema `java_app_test` already exists. Skipping schema creation.
14:12:41.351 [DEBUG] [org.flywaydb.core.internal.dbsupport.Table] Locking table `java_app_test`.`schema_version`...
14:12:41.354 [DEBUG] [org.flywaydb.core.internal.dbsupport.Table] Lock acquired for table `java_app_test`.`schema_version`
14:12:41.358 [INFO] [org.flywaydb.core.internal.command.DbMigrate] Current version of schema `java_app_test`: 1
14:12:41.358 [WARN] [org.flywaydb.core.internal.command.DbMigrate] outOfOrder mode is active. Migration of schema `java_app_test` may not be reproducible.
14:12:41.359 [INFO] [org.flywaydb.core.internal.command.DbMigrate] Schema `java_app_test` is up to date. No migration necessary.
14:12:41.361 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':flywayMigrate'
这里有什么问题?
【问题讨论】:
顺便说一句,无需指定驱动程序。 Flyway 会根据 url 为您自动检测。 【参考方案1】:sqlMigrationPrefix 默认为V
,您的文件不以它开头。重命名文件或将前缀设置为空值。
【讨论】:
【参考方案2】:我遇到了类似的问题,遵循“V1_1__My_description.sql”的文件命名约定解决了这个问题
【讨论】:
【参考方案3】:我遇到了类似的问题。在我的情况下,文件名在版本之后缺少双下划线。
【讨论】:
以上是关于为啥 flyway 会忽略我的 SQL 迁移文件?的主要内容,如果未能解决你的问题,请参考以下文章