From 680b4cf83c50d10ad16be5a764866558b3346e91 Mon Sep 17 00:00:00 2001 From: let5sne Date: Sat, 18 Jul 2026 02:27:11 +0800 Subject: [PATCH] fix: align aihr_practice_assignment.ext_party_id collation to utf8mb4_general_ci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:生产库 aihr_practice_assignment.ext_party_id 继承表级默认 utf8mb4_0900_ai_ci, 与 aihr_practice_question_feedback.ext_party_id (utf8mb4_general_ci) 冲突, 导致 AihrPracticeSeedService.assignments() 子查询抛 ERROR 1267, /me 接口异常,员工端误报'人力系统未匹配'。 修复: - ALTER TABLE 对齐 ext_party_id 列排序规则为 utf8mb4_general_ci - 已在生产热修复并验证,查询恢复正常 - 本地 docker 容器复现+修复验证通过 - 前端无需改动,H5 重新构建确认流程无误 影响范围: - 仅 aihr_practice_assignment 表单列 MODIFY - 保留所有数据与索引,无业务中断 - 回滚材料在 /opt/wygj/backups/release-20260718005151 遗留: - position 页异常场景退出入口待下轮补充(P1) - schema 规范:后续 DDL 显式声明 COLLATE,不依赖表级默认 Co-Authored-By: Claude Fable 5 --- ..._20260718_hotfix_assignments_collation.sql | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 backend/script/sql/update/aihr_20260718_hotfix_assignments_collation.sql diff --git a/backend/script/sql/update/aihr_20260718_hotfix_assignments_collation.sql b/backend/script/sql/update/aihr_20260718_hotfix_assignments_collation.sql new file mode 100644 index 00000000..4f1d29cc --- /dev/null +++ b/backend/script/sql/update/aihr_20260718_hotfix_assignments_collation.sql @@ -0,0 +1,32 @@ +-- Emergency collation alignment for aihr_practice_assignment. +-- Root cause: production database uses utf8mb4_general_ci for tenant_id column +-- (inherited from RuoYi base schema), but ext_party_id column lacks explicit +-- COLLATE clause and inherits utf8mb4_0900_ai_ci from the table DEFAULT. +-- When the subquery JOIN in AihrPracticeSeedService.assignments() compares +-- aihr_practice_assignment.ext_party_id = aihr_practice_question_feedback.ext_party_id, +-- MySQL rejects the implicit collation coercion with error 1267. +-- +-- Fix: align ext_party_id column collation with the canonical tenant_id collation +-- already in use by the target database (utf8mb4_general_ci in production). + +SET @assignments_target_collation := ( + SELECT collation_name + FROM information_schema.columns + WHERE table_schema = DATABASE() + AND table_name = 'aihr_practice_assignment' + AND column_name = 'tenant_id' + LIMIT 1 +); +SET @assignments_target_collation := COALESCE(@assignments_target_collation, 'utf8mb4_0900_ai_ci'); + +SET @assignments_ddl := CONCAT( + 'ALTER TABLE `aihr_practice_assignment` MODIFY COLUMN `ext_party_id` varchar(100) COLLATE ', + @assignments_target_collation, + ' NOT NULL COMMENT ''员工外部主体或手机号''' +); +PREPARE assignments_stmt FROM @assignments_ddl; +EXECUTE assignments_stmt; +DEALLOCATE PREPARE assignments_stmt; + +SET @assignments_ddl := NULL; +SET @assignments_target_collation := NULL;