7a4c9b97d0
Reviewer 复现:cmd/migrate up 接线 ApplyCodesLibMigrations 后,codes 库自建的 codes/codes_batches/codes_audit_log/codes_schema_migrations 四张表不受 golang-migrate 追踪;000020 的 down 脚本做 legacy_codes -> codes 改名回时, 撞上库自建的同名 codes 表,报 "table already exists" 硬失败。 000020 的 sqlite/mysql down 脚本改名前先 DROP TABLE IF EXISTS 掉库自建四张表, 并注明:down = 完整回滚「rename + 库建表」组合,库表数据随 down 销毁属预期 (权威数据仍在 legacy_* 表,回填是后续任务,回填落地后 down 语义需重新审视)。 新增 TestCodesLibMigrateRoundTrip 走真实接线路径(MigrateUp -> ApplyCodesLibMigrations -> 单步撤销 000020 断言 legacy 复原/库表清空 -> 撤销回去 -> 再跑 ApplyCodesLibMigrations 验幂等 -> 全量 store.MigrateDown 即 cmd/migrate down 的真实调用路径,确认不再硬失败)。先用 git stash 掉修复验证 测试能精确复现 reviewer 报的 "table already exists" 报错(RED),再恢复修复 转绿(GREEN)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
14 lines
753 B
SQL
14 lines
753 B
SQL
-- down = 完整回滚「rename + 库建表」组合;库表数据随 down 销毁属预期(此时权威数据仍在
|
|
-- legacy_* 表——回填是后续任务,回填落地后 down 语义需在该任务重新审视并注明)。
|
|
-- 先把 codes 库(github.com/wangjia/codes)自建的表全部清掉,给下面的 RENAME 让位
|
|
-- (up 时是库先建表、这里 down 顺序相反:先拆库表再把 legacy_* 改回原名)。
|
|
DROP TABLE IF EXISTS codes_schema_migrations;
|
|
DROP TABLE IF EXISTS codes_audit_log;
|
|
DROP TABLE IF EXISTS codes;
|
|
DROP TABLE IF EXISTS codes_batches;
|
|
|
|
DROP INDEX idx_legacy_codes_status;
|
|
ALTER TABLE legacy_code_batches RENAME TO code_batches;
|
|
ALTER TABLE legacy_codes RENAME TO codes;
|
|
CREATE INDEX idx_codes_status ON codes (status);
|