fix(db): expand item_snapshot_key to VARCHAR(1024) to prevent Data too long error
- wave_batch.item_snapshot_key: 255 -> 1024, full index -> prefix index(191) - inbox-menu-permissions: INSERT -> INSERT IGNORE for idempotent production rerun
This commit is contained in:
parent
f00b4be1fb
commit
b00e320262
@ -141,9 +141,9 @@ module.exports = app => {
|
||||
comment: '快递名称(区分快递时参与匹配)',
|
||||
},
|
||||
item_snapshot_key: {
|
||||
type: STRING(255),
|
||||
type: STRING(1024),
|
||||
allowNull: true,
|
||||
comment: '结构快照键',
|
||||
comment: '结构快照键(与 item_detail_machine 一致,1024 长度以容纳多商品订单的快照)',
|
||||
},
|
||||
}, {
|
||||
tableName: 'wms_wave_batch',
|
||||
@ -172,7 +172,7 @@ module.exports = app => {
|
||||
},
|
||||
{
|
||||
name: 'idx_wave_snapshot_key',
|
||||
fields: [ 'item_snapshot_key' ],
|
||||
fields: [{ name: 'item_snapshot_key', length: 191 }],
|
||||
},
|
||||
{
|
||||
name: 'idx_wave_item_machine_prefix',
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 新增「消息和自动回复」根菜单及「群列表」「消息记录」子页面。
|
||||
*
|
||||
* 固定 ID(开发库 & 生产库 wms_permission 当前 max_id 均为 491):
|
||||
* 492 — 父级菜单 "消息和自动回复"
|
||||
* 493 — inbox.groups(群列表)
|
||||
* 494 — inbox.messages(消息记录)
|
||||
*
|
||||
* 授权角色(permissions 不为 "*" 的 主管/经理 级角色):
|
||||
* 8 — 经理
|
||||
* 26 — 仓库组-主管
|
||||
* 28 — 客服组-主管
|
||||
* 29 — 生产组-主管
|
||||
*/
|
||||
module.exports = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async up(queryInterface, Sequelize) {
|
||||
// ── 1. 插入父级权限 (type=web_pages, sort=13) ──
|
||||
// 使用 INSERT IGNORE 兼容生产环境已有数据(路径相同但名称可能略有差异)
|
||||
await queryInterface.sequelize.query(`
|
||||
INSERT IGNORE INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at)
|
||||
VALUES (492, '/inbox', NULL, '消息和自动回复', NULL, '消息和自动回复', NULL, 0, 0, NULL, 'web_pages', 13, 1, NOW(), NOW())
|
||||
`);
|
||||
|
||||
// ── 2. 插入子页面权限 ──
|
||||
// 群列表
|
||||
await queryInterface.sequelize.query(`
|
||||
INSERT IGNORE INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at)
|
||||
VALUES (493, '/inbox/groups', NULL, 'inbox.groups', NULL, '群列表', NULL, 0, 0, 492, 'web_pages', 0, 1, NOW(), NOW())
|
||||
`);
|
||||
|
||||
// 消息记录
|
||||
await queryInterface.sequelize.query(`
|
||||
INSERT IGNORE INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at)
|
||||
VALUES (494, '/inbox/messages', NULL, 'inbox.messages', NULL, '消息记录', NULL, 0, 0, 492, 'web_pages', 1, 1, NOW(), NOW())
|
||||
`);
|
||||
|
||||
// ── 3. 给 客服组-主管及以上角色 追加权限 ID(幂等:已包含则跳过)──
|
||||
const newIdSuffix = ', 492, 493, 494';
|
||||
|
||||
await queryInterface.sequelize.query(`
|
||||
UPDATE wms_role
|
||||
SET permissions = CONCAT(LEFT(permissions, LENGTH(permissions) - 1), '${newIdSuffix}]')
|
||||
WHERE id IN (8, 26, 28, 29)
|
||||
AND permissions != '*'
|
||||
AND permissions IS NOT NULL
|
||||
AND LENGTH(permissions) > 2
|
||||
AND permissions NOT LIKE '% 492,%'
|
||||
`);
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async down(queryInterface, Sequelize) {
|
||||
// ── 1. 从角色权限中移除新增的 ID ──
|
||||
await queryInterface.sequelize.query(`
|
||||
UPDATE wms_role
|
||||
SET permissions = REPLACE(permissions, ', 492, 493, 494', '')
|
||||
WHERE id IN (8, 26, 28, 29)
|
||||
`);
|
||||
|
||||
// ── 2. 删除子页面权限 ──
|
||||
await queryInterface.sequelize.query(
|
||||
'DELETE FROM wms_permission WHERE id IN (493, 494)'
|
||||
);
|
||||
|
||||
// ── 3. 删除父级权限 ──
|
||||
await queryInterface.sequelize.query(
|
||||
'DELETE FROM wms_permission WHERE id = 492'
|
||||
);
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 扩大 wms_wave_batch.item_snapshot_key 列容量以容纳多商品订单的快照键。
|
||||
*
|
||||
* 背景:
|
||||
* buildItemSnapshotKey 将订单中每个商品的 stock_id、item_code、
|
||||
* item_name、barcode、quantity 用 :: 拼接,多个商品再用 | 连接。
|
||||
* 当订单包含较多商品或商品名较长时,快照键极易超过原 VARCHAR(255) 上限,
|
||||
* 导致 INSERT 时报 "Data too long for column 'item_snapshot_key'"。
|
||||
*
|
||||
* 变更:
|
||||
* 1. item_snapshot_key: VARCHAR(255) → VARCHAR(1024)
|
||||
* (与 item_detail_machine 容量保持一致)
|
||||
* 2. 索引 idx_wave_snapshot_key: 全列索引 → 前缀索引(191)
|
||||
* (与 idx_wave_item_machine_prefix 前缀长度一致,
|
||||
* 兼容 utf8mb4 下的 InnoDB 索引键长度限制)
|
||||
*/
|
||||
module.exports = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
// ── 1. 先删旧全列索引(否则 changeColumn 1024 会触发 3072 字节限制)──
|
||||
try {
|
||||
await queryInterface.removeIndex('wms_wave_batch', 'idx_wave_snapshot_key');
|
||||
console.log('[migrate] 已移除旧全列索引 idx_wave_snapshot_key');
|
||||
} catch (e) {
|
||||
// 索引可能不存在(如全新库或已执行过),忽略
|
||||
const msg = String(e.message || '');
|
||||
if (!msg.includes('check that it exists') && !msg.includes('exist')) {
|
||||
console.warn('[migrate] 移除索引 idx_wave_snapshot_key 时出现非预期错误:', msg);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 2. 修改列容量 ──
|
||||
await queryInterface.changeColumn('wms_wave_batch', 'item_snapshot_key', {
|
||||
type: Sequelize.STRING(1024),
|
||||
allowNull: true,
|
||||
comment: '结构快照键(与 item_detail_machine 一致,1024 长度以容纳多商品订单的快照)',
|
||||
});
|
||||
console.log('[migrate] wms_wave_batch.item_snapshot_key VARCHAR(255) → VARCHAR(1024)');
|
||||
|
||||
// ── 3. 创建前缀索引 ──
|
||||
try {
|
||||
await queryInterface.sequelize.query(
|
||||
'ALTER TABLE wms_wave_batch ADD INDEX idx_wave_snapshot_key (item_snapshot_key(191))'
|
||||
);
|
||||
console.log('[migrate] 已创建前缀索引 idx_wave_snapshot_key(item_snapshot_key(191))');
|
||||
} catch (e) {
|
||||
if (e.message && e.message.includes('Duplicate')) {
|
||||
console.log('[migrate] 前缀索引 idx_wave_snapshot_key 已存在,跳过');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
// ── 还原索引为全列索引 ──
|
||||
try {
|
||||
await queryInterface.removeIndex('wms_wave_batch', 'idx_wave_snapshot_key');
|
||||
console.log('[migrate:down] 已移除前缀索引 idx_wave_snapshot_key');
|
||||
} catch (e) {
|
||||
if (!(e.message && e.message.includes('check that it exists'))) {
|
||||
console.warn('[migrate:down] 移除索引时出现非预期错误:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await queryInterface.sequelize.query(
|
||||
'ALTER TABLE wms_wave_batch ADD INDEX idx_wave_snapshot_key (item_snapshot_key)'
|
||||
);
|
||||
console.log('[migrate:down] 已还原全列索引 idx_wave_snapshot_key');
|
||||
} catch (e) {
|
||||
if (e.message && e.message.includes('Duplicate')) {
|
||||
console.log('[migrate:down] 全列索引 idx_wave_snapshot_key 已存在,跳过');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// ── 还原列容量 ──
|
||||
await queryInterface.changeColumn('wms_wave_batch', 'item_snapshot_key', {
|
||||
type: Sequelize.STRING(255),
|
||||
allowNull: true,
|
||||
comment: '结构快照键',
|
||||
});
|
||||
console.log('[migrate:down] wms_wave_batch.item_snapshot_key VARCHAR(1024) → VARCHAR(255)');
|
||||
},
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user