Flyway 无法检测到新的迁移文件
Flyway fails to detect new migration files
在添加新的迁移文件后,我正在尝试 运行 来自 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
:-)
您的配置中有 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 的原因
在添加新的迁移文件后,我正在尝试 运行 来自 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
:-)
您的配置中有 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 的原因