pipeline-app/deploy/migrations/m0038_pipeline_user_secrets_unique_index.json
yumoqing 66996c693d fix(dmig): DROP INDEX 被 DROP COLUMN 守卫误解析致静默跳过 + m0038 唯一索引修正
dmig.py 两处(2026-09-17 m0038 部署预演时本地测试抓到):
① `ALTER TABLE t DROP INDEX idx` 会命中 DROP COLUMN 守卫的可选 `(COLUMN\s+)?`
   分支,group(3) 捕获到字面词 'INDEX' 而非索引名 → column_exists(t,'INDEX')
   恒 False → 整步被静默跳过(索引删不掉、无任何报错)。修: DROP INDEX 守卫
   (ALTER 形态 + 独立 `DROP INDEX idx ON t` 形态,历史迁移 m0025/m0031 等
   13 条 down 段用的就是独立形态、此前同样无守卫)放在 DROP COLUMN 之前,
   幂等判据用 index_exists。
② DROP COLUMN 正则收紧为强制 COLUMN 关键字后列名组号 3→2,调用点同步
   (历史 22 条 DROP COLUMN 全部显式带 COLUMN、bare 形态 0 条,无回归)。
本地守卫测试 18/18 全绿(含 m0038 up/down/重复down 完整生命周期)。

m0038: m0037 把 models 声明的 uk_org_user_name(unique) 误写成普通 CREATE
INDEX → 实测建出 KEY 而非 UNIQUE KEY,失去并发去重保护(同名可插重复行、
save_secret 幂等判定失效)。本迁移删误建索引并按 models JSON 权威定义重建
UNIQUE。backup_tables 照旧。不改已应用的 m0037(台账完整性)。
2026-09-17 16:02:33 +08:00

26 lines
1.1 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"id": "m0038",
"title": "修正 pipeline_user_secrets 唯一索引(2026-09-17): m0037 把 models 声明的 uk_org_user_name(unique) 误写成普通 CREATE INDEX → 实测建出 KEY 而非 UNIQUE KEY,失去并发去重保护(同名可插重复行、幂等判定失效)。本迁移删除误建的普通索引并按 models JSON 权威定义重建为 UNIQUE。DROP INDEX 用不带 IF EXISTS 的形态(MariaDB 10.6 对 DROP INDEX IF EXISTS 支持不确定,不赌语法),dmig 的 index_exists 守卫已覆盖幂等",
"backup_tables": ["pipeline_user_secrets"],
"up": [
{
"op": "sql",
"sql": "ALTER TABLE pipeline_user_secrets DROP INDEX pipeline_user_secrets_idx_org_user_name"
},
{
"op": "sql",
"sql": "CREATE UNIQUE INDEX uk_org_user_name ON pipeline_user_secrets(org_id, user_id, name)"
}
],
"down": [
{
"op": "sql",
"sql": "ALTER TABLE pipeline_user_secrets DROP INDEX uk_org_user_name"
},
{
"op": "sql",
"sql": "CREATE INDEX pipeline_user_secrets_idx_org_user_name ON pipeline_user_secrets(org_id, user_id, name)"
}
]
}