oms/backend/database/migrations/20260909000105-create-menus.js

49 lines
1.8 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';
/** 6. 菜单表:通用菜单/权限资源,不区分主体 */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(
'menus',
{
id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
parent_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '父菜单ID,0 表示根节点',
},
name: { type: Sequelize.STRING(50), allowNull: false, comment: '菜单名称' },
type: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '类型:1目录 2菜单 3按钮' },
path: { type: Sequelize.STRING(200), allowNull: true, comment: '前端路由/地址' },
icon: { type: Sequelize.STRING(100), allowNull: true, comment: '图标' },
permission: { type: Sequelize.STRING(100), allowNull: true, comment: '权限标识,如 order:create' },
sort: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comment: '排序' },
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
},
},
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '菜单表' }
);
await queryInterface.addIndex('menus', { fields: [ 'parent_id' ], name: 'idx_menus_parent' });
},
async down(queryInterface) {
await queryInterface.dropTable('menus');
},
};