- 列表/详情不再用 Sequelize include 关联 express_companies(该 JOIN 在两边排序规则不同时报 ER_CANT_AGGREGATE_2COLLATIONS),改为一次 IN 查询后在内存组装,响应仍保留 expressCompany/express_name - 新增迁移把未显式指定字符集的字典/任务表统一为 utf8mb4 / utf8mb4_unicode_ci (custom_express_codes、external_print_express_interfaces、warehouse_express_mappings、 waybill_fetch_records、order_sync_tasks、shop_database_configs、operation_logs、openapi_request_idempotency) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 统一「字典表 / 任务表」的字符集与排序规则
|
||
*
|
||
* 这些表当初建表时没有显式指定 charset/collate,字符集由数据库默认值决定:
|
||
* - 本地/部分环境默认是 utf8mb3(utf8_general_ci)
|
||
* - 另一些环境默认是 utf8mb4(utf8mb4_general_ci 或 utf8mb4_0900_ai_ci)
|
||
* 而 `express_companies` 等核心字典表固定为 utf8mb4 / utf8mb4_unicode_ci。
|
||
*
|
||
* 只要两边同字符集但排序规则不同,MySQL 在 JOIN / 比较时直接报
|
||
* `ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations`(自定义快递编码列表 500 即由此触发),
|
||
* 因此这里把相关表统一转换成 utf8mb4 / utf8mb4_unicode_ci。
|
||
*/
|
||
const TABLES = [
|
||
'custom_express_codes',
|
||
'external_print_express_interfaces',
|
||
'warehouse_express_mappings',
|
||
'waybill_fetch_records',
|
||
'order_sync_tasks',
|
||
'shop_database_configs',
|
||
'operation_logs',
|
||
'openapi_request_idempotency',
|
||
];
|
||
|
||
module.exports = {
|
||
async up(queryInterface) {
|
||
const existTables = new Set(await queryInterface.showAllTables());
|
||
for (const table of TABLES) {
|
||
if (!existTables.has(table)) continue;
|
||
await queryInterface.sequelize.query(
|
||
`ALTER TABLE \`${table}\` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`
|
||
);
|
||
}
|
||
},
|
||
|
||
// 字符集统一属于修复性变更(回滚会重新引入排序规则冲突导致 JOIN 报错),故不做反向操作
|
||
async down() {
|
||
return Promise.resolve();
|
||
},
|
||
};
|