chore(迁移): 新增 V136 版本表 is_latest、V137 隐藏 20 个冗余索引;登记 V132/V133 退役空号
两个迁移原本按 V132/V133 取号,但生产 flyway_schema_history 已执行到 V135(V134/V135 于 2026-09-25 落库),应用没开 out-of-order,低号新迁移会让 validate-on-migrate 直接报 "Detected resolved migration not applied to database" 并启动失败,因此顺排到 V136/V137。 空号无法回收,MigrationInventoryTest 的「1..N 连续」断言改为显式登记 RETIRED_HOLES, 并要求迁移清单文档记录空号来历——否则后来人会试图回填这两个号。 V136:web_config 只追加、从不记录哪条是最新版,读取侧靠 ORDER BY created_at DESC 现场算; 一旦有人补插 created_at 较早的行,/api/version/latest 会把全体客户端指回旧包且不报错。 回填语句按同一排序取一行、不写死 id,迁移前后接口返回值逐字节一致。 V137:20 个「列是另一索引严格左前缀」的二级索引置 INVISIBLE 而非 DROP——前缀规则只保证 可用性不保证代价相同,且 aiimage 账号读不了 performance_schema(1142),没法先量出哪些查询 真在做覆盖扫描,所以先隐藏观察,一条语句即可还原。
This commit is contained in:
@@ -8,6 +8,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -23,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* task-193:历史迁移盘点审计(只读)。
|
||||
* 校验 src/main/resources/db 版本化迁移:整数版本 1..max 连续、无重复、命名合规、
|
||||
* 校验 src/main/resources/db 版本化迁移:整数版本 1..max 连续(RETIRED_HOLES 除外)、无重复、命名合规、
|
||||
* 历史小版本(V25_1)被识别、校验和可复算稳定;产出 docs/migration-inventory.md 快照已提交。
|
||||
*/
|
||||
class MigrationInventoryTest {
|
||||
@@ -66,15 +67,28 @@ class MigrationInventoryTest {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 已在生产 flyway_schema_history 中占位、但本地文件被改名让位的版本号。
|
||||
* 生产 131 之后直接装了 134/135(2026-09-25 20:46:16),132/133 从未落库;
|
||||
* 而 Flyway 未开 out-of-order,把新迁移编号改回 132/133 会导致启动期
|
||||
* "resolved migration not applied" 失败,所以这个洞只能永久保留、不能回填。
|
||||
* 后果:新迁移只能取当前最大值之上的号(详见 docs/migration-inventory.md)。
|
||||
*/
|
||||
private static final Set<Integer> RETIRED_HOLES = Set.of(132, 133);
|
||||
|
||||
@Test
|
||||
void integerVersionsSequentialFromOne() throws IOException {
|
||||
List<Migration> all = parseAll(versionFiles());
|
||||
List<Integer> integers = all.stream().filter(Migration::isInteger)
|
||||
.map(Migration::major).sorted().toList();
|
||||
for (int i = 0; i < integers.size(); i++) {
|
||||
assertEquals(i + 1, integers.get(i), "整数版本应 1..N 连续,出现断号");
|
||||
Set<Integer> actual = new HashSet<>(integers);
|
||||
assertTrue(Collections.disjoint(actual, RETIRED_HOLES), "退役号段不应出现本地迁移文件");
|
||||
int max = integers.get(integers.size() - 1);
|
||||
for (int v = 1; v <= max; v++) {
|
||||
assertTrue(actual.contains(v) || RETIRED_HOLES.contains(v),
|
||||
"整数版本应 1..max 连续(除已登记的退役洞),缺 V" + v);
|
||||
}
|
||||
assertEquals(integers.size(), integers.get(integers.size() - 1), "整数版本应以 max 收尾且覆盖 1..max");
|
||||
assertEquals(max - RETIRED_HOLES.size(), integers.size(), "不应有重复版本号占位");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,8 +132,14 @@ class MigrationInventoryTest {
|
||||
Path doc = Path.of(System.getProperty("user.dir"), "docs/migration-inventory.md");
|
||||
assertTrue(Files.exists(doc), "盘点文档应存在并随仓库提交");
|
||||
String text = Files.readString(doc);
|
||||
assertTrue(text.contains("V108"), "文档应记录最新版本");
|
||||
int maxMajor = parseAll(versionFiles()).stream().filter(Migration::isInteger)
|
||||
.mapToInt(Migration::major).max().orElse(0);
|
||||
assertTrue(text.contains("V" + maxMajor), "文档应记录最新版本 V" + maxMajor);
|
||||
assertTrue(text.contains("25_1") || text.contains("V25_1"), "文档应记录历史小版本");
|
||||
for (int hole : RETIRED_HOLES) {
|
||||
assertTrue(text.contains(String.valueOf(hole)),
|
||||
"文档应记录退役空号 V" + hole + " 的来历,否则后来人会试图回填该号");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user