'use strict'; /** * 新增「权限管理」菜单:挂在「系统管理」目录下(组织架构与账号之间)。 * 按 name + parent_id 判重,可重复执行。 */ const PARENT_NAME = '系统管理'; const MENU = { name: '权限管理', type: 2, path: '/system/permission', icon: 'Lock', permission: 'permission:list', component: 'views/Permission/Index.vue', sort: 75, }; module.exports = { async up(queryInterface) { const sequelize = queryInterface.sequelize; const parent = await sequelize.query( 'SELECT id FROM menus WHERE name = ? AND parent_id = 0 LIMIT 1', { replacements: [ PARENT_NAME ], type: sequelize.QueryTypes.SELECT } ); const parentRow = parent[0]; if (!parentRow) return; const parentId = Number(parentRow.id); const exist = await sequelize.query( 'SELECT id FROM menus WHERE name = ? AND parent_id = ? LIMIT 1', { replacements: [ MENU.name, parentId ], type: sequelize.QueryTypes.SELECT } ); if (exist[0]) return; await sequelize.query( `INSERT INTO menus (parent_id, name, type, path, icon, permission, component, sort, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, NOW(), NOW())`, { replacements: [ parentId, MENU.name, MENU.type, MENU.path, MENU.icon, MENU.permission, MENU.component, MENU.sort, ], } ); }, async down(queryInterface) { await queryInterface.sequelize.query('DELETE FROM menus WHERE name = ? AND path = ?', { replacements: [ MENU.name, MENU.path ], }); }, };