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;