fix: 项目备份/删除 SQL 跨表 collation 不匹配——general_ci 表比较列统一 COLLATE utf8mb4_unicode_ci
This commit is contained in:
parent
06ae6bb1ac
commit
5d40cdcd16
@ -193,12 +193,12 @@ async def _dump_project_records(sor, project_id):
|
||||
'sd_projects': "SELECT * FROM sd_projects WHERE id=${pid}$",
|
||||
'sd_iterations': "SELECT * FROM sd_iterations WHERE project_id=${pid}$",
|
||||
'pipeline_tasks': "SELECT * FROM pipeline_tasks WHERE tenant_id=${pid}$",
|
||||
'pipeline_deliverables': "SELECT * FROM pipeline_deliverables WHERE project_id=${pid}$",
|
||||
'pipeline_project_agents': "SELECT * FROM pipeline_project_agents WHERE project_id=${pid}$",
|
||||
'pipeline_deliverables': "SELECT * FROM pipeline_deliverables WHERE project_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
'pipeline_project_agents': "SELECT * FROM pipeline_project_agents WHERE project_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
'pipeline_agent_questions': "SELECT * FROM pipeline_agent_questions WHERE tenant_id=${pid}$",
|
||||
'sd_deploy_envs': "SELECT * FROM sd_deploy_envs WHERE project_id=${pid}$",
|
||||
'sd_features': "SELECT * FROM sd_features WHERE project_id=${pid}$",
|
||||
'sd_project_repos': "SELECT * FROM sd_project_repos WHERE project_id=${pid}$",
|
||||
'sd_project_repos': "SELECT * FROM sd_project_repos WHERE project_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
}
|
||||
for tbl, sql in direct.items():
|
||||
try:
|
||||
@ -212,9 +212,9 @@ async def _dump_project_records(sor, project_id):
|
||||
'sd_bugs': "SELECT * FROM sd_bugs WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
'sd_test_plans': "SELECT * FROM sd_test_plans WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
'sd_test_cases': "SELECT * FROM sd_test_cases WHERE plan_id IN (SELECT id FROM sd_test_plans WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$))",
|
||||
'sd_conversations': "SELECT * FROM sd_conversations WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
'pipeline_conversations': "SELECT * FROM pipeline_conversations WHERE iteration_id=${pid}$ OR iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
'audit_log': "SELECT * FROM audit_log WHERE tenant_id=${pid}$ ORDER BY created_at ASC",
|
||||
'sd_conversations': "SELECT * FROM sd_conversations WHERE iteration_id COLLATE utf8mb4_unicode_ci IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
'pipeline_conversations': "SELECT * FROM pipeline_conversations WHERE iteration_id COLLATE utf8mb4_unicode_ci=${pid}$ OR iteration_id COLLATE utf8mb4_unicode_ci IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
'audit_log': "SELECT * FROM audit_log WHERE tenant_id COLLATE utf8mb4_unicode_ci=${pid}$ ORDER BY created_at ASC",
|
||||
}
|
||||
for tbl, sql in indirect.items():
|
||||
try:
|
||||
@ -315,22 +315,22 @@ async def delete_project(project_id, who=None, agent_id=None, confirm=False):
|
||||
"DELETE FROM sd_test_cases WHERE plan_id IN (SELECT id FROM sd_test_plans WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$))",
|
||||
"DELETE FROM sd_bugs WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
"DELETE FROM sd_test_plans WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
"DELETE FROM sd_conversations WHERE iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
"DELETE FROM pipeline_conversations WHERE iteration_id=${pid}$ OR iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
"DELETE FROM sd_conversations WHERE iteration_id COLLATE utf8mb4_unicode_ci IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
"DELETE FROM pipeline_conversations WHERE iteration_id COLLATE utf8mb4_unicode_ci=${pid}$ OR iteration_id COLLATE utf8mb4_unicode_ci IN (SELECT id FROM sd_iterations WHERE project_id=${pid}$)",
|
||||
]
|
||||
for sql in indirect:
|
||||
await sor.sqlExe(sql, {"pid": project_id})
|
||||
|
||||
# 3. 删除直接关联表(project_id / tenant_id)
|
||||
direct = [
|
||||
"DELETE FROM pipeline_deliverables WHERE project_id=${pid}$",
|
||||
"DELETE FROM pipeline_project_agents WHERE project_id=${pid}$",
|
||||
"DELETE FROM pipeline_deliverables WHERE project_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
"DELETE FROM pipeline_project_agents WHERE project_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
"DELETE FROM pipeline_agent_questions WHERE tenant_id=${pid}$",
|
||||
"DELETE FROM sd_deploy_envs WHERE project_id=${pid}$",
|
||||
"DELETE FROM sd_features WHERE project_id=${pid}$",
|
||||
"DELETE FROM sd_project_repos WHERE project_id=${pid}$",
|
||||
"DELETE FROM sd_project_repos WHERE project_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
"DELETE FROM pipeline_tasks WHERE tenant_id=${pid}$",
|
||||
"DELETE FROM audit_log WHERE tenant_id=${pid}$",
|
||||
"DELETE FROM audit_log WHERE tenant_id COLLATE utf8mb4_unicode_ci=${pid}$",
|
||||
"DELETE FROM sd_iterations WHERE project_id=${pid}$",
|
||||
"DELETE FROM sd_projects WHERE id=${pid}$",
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user