fix(test): codes-lib 迁移往返测试改用 m.Migrate(21) 显式定位版本
Deploy Server / deploy-server (push) Failing after 41s

TestCodesLibMigrateRoundTrip 硬编码 6 次 Steps(-1),假设 000027 是迁移栈顶;本功能
加了 000028_routing_profiles 后 6 步落在版本 22、跳过了 000022 down,导致断言失败。
根因不是迁移 SQL(000022 up/down 正确、codes-lib 表无 FK——推翻了 FK 假设),而是
测试的脆弱步数计数被新增迁移打乱。改用 m.Migrate(21) 显式降到 000022 down 之后的
边界,不受栈顶新增迁移影响。全仓 go test ./... 恢复 0 FAIL。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo
This commit is contained in:
wangjia
2026-07-29 07:08:56 +08:00
parent 2930d76cf3
commit a307c6ca2c
@@ -104,29 +104,12 @@ func TestCodesLibMigrateRoundTrip(t *testing.T) {
// the reviewer's repro hit: the lib's `codes` table collides with the
// name 000022's down script renames legacy_codes back to.
m := newSQLiteStepper(t, db)
// 000027 (pay_promo_paid_unique), 000026 (notices), 000025
// (user_device_limit_override), 000024 (invite_rewards) and 000023
// (pay_purchases/source-enum) now sit on top of 000022
// (codes_lib_legacy_rename) and are unrelated to this collision — step
// them back down first so we land exactly on the 000022 boundary the
// test targets.
if err := m.Steps(-1); err != nil {
t.Fatalf("step 000027 down: %v", err)
}
if err := m.Steps(-1); err != nil {
t.Fatalf("step 000026 down: %v", err)
}
if err := m.Steps(-1); err != nil {
t.Fatalf("step 000025 down: %v", err)
}
if err := m.Steps(-1); err != nil {
t.Fatalf("step 000024 down: %v", err)
}
if err := m.Steps(-1); err != nil {
t.Fatalf("step 000023 down: %v", err)
}
if err := m.Steps(-1); err != nil {
t.Fatalf("step 000022 down: %v (this is the reviewer-reported collision — "+
// 所有排在 000022 之上的迁移(000023..最新,如 pay_purchases / invite_rewards /
// notices / routing_profiles …)都与本冲突无关 —— 一次性降到版本 21,恰好落在
// 000022(codes_lib_legacy_rename)down 之后的边界。用版本号显式定位而非硬编码
// Steps(-1) 计数,避免栈顶新增迁移(如 000028)后步数漂移、跳过 000022 down。
if err := m.Migrate(21); err != nil {
t.Fatalf("migrate down to v21 (past 000022 down): %v (this is the reviewer-reported collision — "+
"000022 down must DROP the codes-lib tables before renaming legacy_* back)", err)
}