feat(migration): m0023 pipeline_user_memory 多租户(加org_id/user_id列+存量key重算+归属索引)

This commit is contained in:
yumoqing 2026-09-10 17:09:46 +08:00
parent 9674a2ee4b
commit b7c6d8b8fb

View File

@ -0,0 +1,16 @@
{
"id": "m0023",
"title": "pipeline_user_memory 多租户隔离:加 org_id/user_id 归属列 + 存量 memory_key 重算(新 key 掺租户/作用域维度,防跨租户唯一键碰撞)+ 归属查询索引",
"backup_tables": ["pipeline_user_memory"],
"up": [
{"op": "sql", "sql": "ALTER TABLE pipeline_user_memory ADD COLUMN org_id varchar(32) NOT NULL DEFAULT '' AFTER scope_id"},
{"op": "sql", "sql": "ALTER TABLE pipeline_user_memory ADD COLUMN user_id varchar(32) NOT NULL DEFAULT '' AFTER org_id"},
{"op": "sql", "sql": "UPDATE pipeline_user_memory SET memory_key = LEFT(MD5(CONCAT(content, '|org=', org_id, '|user=', user_id, '|scope=', scope, '|sid=', scope_id)), 16)"},
{"op": "sql", "sql": "CREATE INDEX idx_memory_org_user ON pipeline_user_memory (org_id, user_id)"}
],
"down": [
{"op": "sql", "sql": "UPDATE pipeline_user_memory SET memory_key = LEFT(MD5(content), 16)"},
{"op": "sql", "sql": "ALTER TABLE pipeline_user_memory DROP COLUMN user_id"},
{"op": "sql", "sql": "ALTER TABLE pipeline_user_memory DROP COLUMN org_id"}
]
}