WMS_MAIN/database/migrations/20260805130000-add-inbox-menu-permissions.js
liufumingren b00e320262 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
2026-08-05 22:46:22 +08:00

74 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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'
);
},
};