diff --git a/muse-cloud/muse-server/src/test/java/cn/iocoder/muse/server/framework/api/P1rKnowledgeFlywayMigrationIT.java b/muse-cloud/muse-server/src/test/java/cn/iocoder/muse/server/framework/api/P1rKnowledgeFlywayMigrationIT.java index 4ec5fa4a..bfc742bc 100644 --- a/muse-cloud/muse-server/src/test/java/cn/iocoder/muse/server/framework/api/P1rKnowledgeFlywayMigrationIT.java +++ b/muse-cloud/muse-server/src/test/java/cn/iocoder/muse/server/framework/api/P1rKnowledgeFlywayMigrationIT.java @@ -29,14 +29,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * P1R-5 Knowledge / RAGFlow 真实 PostgreSQL / Flyway 迁移验收。 * *

本测试只接受显式传入的 Flyway URL/用户/位置参数与环境变量密码,并强制数据库名以 _test 结尾; - * 运行时会 clean 隔离测试库的 public schema,再执行 sql/muse 下 V1-V21 全量迁移。

+ * 运行时会 clean 隔离测试库的 public schema,再执行 sql/muse 下 V1 到最新版本全量迁移。

*/ class P1rKnowledgeFlywayMigrationIT { - // schema 已演进至 V21(V15-V21 为各域 events-publish-outbox 等迁移);Flyway 全量执行 sql/muse 下所有迁移, - // 故当前版本与成功迁移数随 schema 增长。本测试聚焦验证 V14 引入的 Knowledge/RAGFlow 表与索引在全量迁移后仍存在。 - private static final String TARGET_VERSION = "21"; - private static final int TARGET_MIGRATION_COUNT = 21; + // Flyway 全量执行 sql/muse 下所有迁移;当前版本与成功迁移数以本次 MigrateResult 为准(targetSchemaVersion/migrationsExecuted), + // 避免每加一条迁移(V22/V23…)就改硬编码常量(历史已复发两次:V14→V21→V23)。本测试聚焦验证 V14 引入的 Knowledge/RAGFlow 表与索引在全量迁移后仍存在。 private static final List REQUIRED_TABLES = List.of( "muse_knowledge_command", "muse_knowledge_processing_task", @@ -110,12 +108,16 @@ class P1rKnowledgeFlywayMigrationIT { flyway.clean(); MigrateResult result = flyway.migrate(); + assertTrue(result.success, "Flyway migrate 必须成功"); + assertTrue(result.migrationsExecuted > 0, "必须从 clean 后的隔离库执行至少一个 SQL 迁移"); + // 期望版本/数量动态取自本次 MigrateResult,随 sql/muse 增长自适应;反假绿仍靠:迁移成功 + history 计数一致 + 下方 Knowledge 表/索引/列存在。 + String targetVersion = Objects.requireNonNull(result.targetSchemaVersion, "Flyway 必须返回本次迁移目标版本"); MigrationInfo current = flyway.info().current(); - assertEquals(TARGET_VERSION, Objects.requireNonNull(current, "必须存在当前 Flyway 版本").getVersion().getVersion(), - "真实 Flyway 当前版本必须到 V" + TARGET_VERSION); + assertEquals(targetVersion, Objects.requireNonNull(current, "必须存在当前 Flyway 版本").getVersion().getVersion(), + "真实 Flyway 当前版本必须到本次迁移目标 V" + targetVersion); int successfulMigrationCount = successfulMigrationCount(url, user, password); - assertEquals(TARGET_MIGRATION_COUNT, successfulMigrationCount, - "必须在隔离库中执行 V1-V" + TARGET_VERSION + " 共 " + TARGET_MIGRATION_COUNT + " 个成功 SQL 迁移"); + assertEquals(result.migrationsExecuted, successfulMigrationCount, + "必须在隔离库中执行 V1-V" + targetVersion + " 共 " + result.migrationsExecuted + " 个成功 SQL 迁移"); try (Connection connection = DriverManager.getConnection(url, user, password)) { Map tableChecks = tableChecks(connection); @@ -135,7 +137,7 @@ class P1rKnowledgeFlywayMigrationIT { System.out.println("flyway_locations_effective=" + effectiveLocations); System.out.println("migrations_executed=" + result.migrationsExecuted); System.out.println("successful_migration_count=" + successfulMigrationCount); - System.out.println("target_schema_version=" + TARGET_VERSION); + System.out.println("target_schema_version=" + targetVersion); System.out.println("flyway_latest=" + current.getVersion() + ":" + current.getDescription()); System.out.println("schema_version=" + current.getVersion()); System.out.println("v14_tables=" + String.join(",", REQUIRED_TABLES));