添加新的迁移文件后,我试图在我的项目中从Gradle运行flywayMigrate
任务,但Flyway不会选择它。我得到以下输出:
Flyway Community Edition 5.2.4 by Boxfuse
Database: jdbc:postgresql://localhost:5432/mydb (PostgreSQL 10.6)
Successfully validated 6 migrations (execution time 00:00.105s)
Current version of schema "public": 5
Schema "public" is up to date. No migration necessary.
因此它检测到我进行了 6 迁移,但是它不执行我刚刚添加的新文件(V6
),并坚持说该架构是最新的,即使不是。
这是我的配置的样子:
{
url = database_url
user = database_user
password = database_password
driver = database_driver
schemas = ["public"]
locations = ["filesystem:shared/src/main/resources/db/migration"]
table = "flyway_schema_history"
sqlMigrationPrefix = "V"
sqlMigrationSuffix = ".sql"
placeholderPrefix = "\${"
placeholderSuffix = "}"
target = "5.1"
}
我检查了所有设置,都可以,如果我删除了所有表,它将拾取第一个 5 迁移文件,但是由于某些原因未选择第 6 个迁移文件起来(我什至尝试添加第7个,但也不起作用)
我尝试在第6个迁移文件中运行sql
,并且运行正常,因此Flyway可能存在问题。
如果我使用debug
标志运行,我可以看到它甚至可以解析并从文件中读取sql,但是所有迁移都被过滤掉了。我在做什么错了?
...
15:23:34.893 [DEBUG] [org.flywaydb.core.internal.sqlscript.SqlScript] Parsing V5__some_migration_5.sql ...
15:23:34.893 [DEBUG] [org.flywaydb.core.internal.sqlscript.SqlScript] Found statement at line 1: ...
...
15:23:34.894 [DEBUG] [org.flywaydb.core.internal.sqlscript.SqlScript] Parsing V6__some_migration_6.sql ...
15:23:34.894 [DEBUG] [org.flywaydb.core.internal.sqlscript.SqlScript] Found statement at line 1: ...
15:23:34.894 [DEBUG] [org.flywaydb.core.internal.scanner.Scanner] Filtering out resource: shared/src/main/resources/db/migration/V1__some_migration_1.sql (filename: V1__some_migration_1.sql)
15:23:34.895 [DEBUG] [org.flywaydb.core.internal.scanner.Scanner] Filtering out resource: shared/src/main/resources/db/migration/V2__some_migration_2.sql (filename: V2__some_migration_2.sql)
15:23:34.895 [DEBUG] [org.flywaydb.core.internal.scanner.Scanner] Filtering out resource: shared/src/main/resources/db/migration/V3__some_migration_3.sql (filename: V3__some_migration_3.sql)
15:23:34.895 [DEBUG] [org.flywaydb.core.internal.scanner.Scanner] Filtering out resource: shared/src/main/resources/db/migration/V4__some_migration_4.sql (filename: V4__some_migration_4.sql)
15:23:34.895 [DEBUG] [org.flywaydb.core.internal.scanner.Scanner] Filtering out resource: shared/src/main/resources/db/migration/V5__some_migration_5.sql (filename: V5__some_migration_5.sql)
15:23:34.895 [DEBUG] [org.flywaydb.core.internal.scanner.Scanner] Filtering out resource: shared/src/main/resources/db/migration/V6__some_migration_6.sql (filename: V6__some_migration_6.sql)
15:23:34.899 [DEBUG] [org.postgresql.jdbc.PgConnection] setAutoCommit = true
15:23:34.899 [INFO] [org.flywaydb.core.internal.command.DbValidate] Successfully validated 6 migrations (execution time 00:00.016s)
15:23:34.899 [DEBUG] [org.postgresql.jdbc.PgConnection] setAutoCommit = false
15:23:34.899 [DEBUG] [org.flywaydb.core.internal.command.DbSchemas] Schema "public" already exists. Skipping schema creation.
15:23:34.900 [DEBUG] [org.postgresql.jdbc.PgConnection] setAutoCommit = true
15:23:34.915 [INFO] [org.flywaydb.core.internal.command.DbMigrate] Current version of schema "public": 5
15:23:34.915 [INFO] [org.flywaydb.core.internal.command.DbMigrate] Schema "public" is up to date. No migration necessary.
我在flyway_schema_history
中看到的与日志所说的一致:
installed_rank version description type script checksum installed_by installed_on execution_time success
1 1 some migration 1 SQL V1__some_migration_1.sql 1640479949 myuser 2019-05-31 15:17:19.354850 26 true
2 2 some migration 2 SQL V2__some_migration_2.sql 1463373644 myuser 2019-05-31 15:17:19.394065 1 true
3 3 some migration 3 SQL V3__some_migration_3.sql 1872028758 myuser 2019-05-31 15:17:19.398957 9 true
4 4 some migration 4 SQL V4__some_migration_4.sql 762610066 myuser 2019-05-31 15:17:19.410718 5 true
5 5 some migration 5 SQL V5__some_migration_5.sql -355256115 myuser 2019-05-31 15:17:19.418077 1 true
答案 0 :(得分:1)
:-)
您的配置中有target = "5.1"
,但
target NO latest version
The target version up to which Flyway should run migrations.
Migrations with a higher version number will not be applied.
The string 'current' will be interpreted as MigrationVersion.CURRENT,
a placeholder for the latest version that has been applied to the database.
这就是为什么您无法处理迁移> 5.1