Chl*_*loe 8 java flyway spring-boot
我有一个现有的数据库。我创建了两个迁移
$ ls src/main/resources/db/migration/
V1__create_stats.sql V2__create_sources.sql
Run Code Online (Sandbox Code Playgroud)
我设置了以下内容 application.properties
# Prevent complaints when starting migrations with existing tables.
flyway.baselineOnMigrate = true
Run Code Online (Sandbox Code Playgroud)
否则它会给出错误org.flywaydb.core.api.FlywayException: Found non-empty schemagalaxybadgewithout metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
当我尝试启动应用程序时,它会跳过迁移并且不执行它们!我show tables;在 MySQL 中使用,看到它们不在那里!
>mvn spring-boot:run
...
2018-05-09 18:43:03.671 INFO 24520 --- [ restartedMain] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
2018-05-09 18:43:04.420 INFO 24520 --- [ restartedMain] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:mysql://localhost:3306/galaxybadge (MySQL 5.5)
2018-05-09 18:43:04.486 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbValidate : Validated 0 migrations (execution time 00:00.030s)
2018-05-09 18:43:04.704 INFO 24520 --- [ restartedMain] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: `galaxybadge`.`schema_version`
2018-05-09 18:43:05.116 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbBaseline : Schema baselined with version: 1
2018-05-09 18:43:05.145 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Current version of schema `galaxybadge`: 1
2018-05-09 18:43:05.146 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Schema `galaxybadge` is up to date. No migration necessary.
Run Code Online (Sandbox Code Playgroud)
我看了这个答案,但它没有帮助,似乎给出了错误的属性名称。这是schema_version它创建的表。
> select * from schema_version;
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| version_rank | installed_rank | version | description | type | script | checksum | installed_by | installed_on | execution_time | success |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| 1 | 1 | 1 | << Flyway Baseline >> | BASELINE | << Flyway Baseline >> | NULL | root | 2018-05-09 18:43:05 | 0 | 1 |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
Run Code Online (Sandbox Code Playgroud)
Spring Boot 1.5.6,FlyWay 核心 3.2.1
好的,我找到了这个https://flywaydb.org/documentation/existing
但没有遵循它。相反,我将迁移移入V1__*和V2__*移至V2...,V3...并将生产模式下载到V1__initialize.sql.
mysqldump -h project.us-east-1.rds.amazonaws.com -u username -p --no-data --skip-add-drop-table --compact --skip-set-charset databasename > V1__initialize.sql
Run Code Online (Sandbox Code Playgroud)
然后,当我运行 Spring 时,mvn spring-boot:run它运行了迁移。
(实际上,对 SQL 进行了大量调试,我不得不多次删除表并从中删除行schema_verion并从中删除旧文件名target/.../migration/,但那是另一个故事了。)
我相信可以设置
flyway.baselineVersion=0
Run Code Online (Sandbox Code Playgroud)
并根据此处的信息跳过 SQL 转储(初始化): https: //flywaydb.org/documentation/configfiles。然而,为未来的开发人员提供可用的架构似乎是正确的方法。
我仍然不明白为什么它没有V2__...从最初的问题进行迁移。如果它从 1 开始,则迁移 2 仍然可以运行。如果它按预期工作,那么我可能会更快地理解问题。
| 归档时间: |
|
| 查看次数: |
5414 次 |
| 最近记录: |