Files
framework_project_web/migrations/init.sql
张成 b7208545e3 1
2026-04-29 13:46:24 +08:00

128 lines
6.7 KiB
SQL
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.
-- 与 sql/init.sql 同步(内容一致)
-- =============================================================================
-- 前后端项目模板 · 初始化库表与基础数据MySQL 5.7+ / 8.xutf8mb4
-- 执行前请创建空库并 USE 到目标 database会 DROP 后重建系统表,请勿在生产库直接全量执行。
-- 默认管理员admin / 123456密码为 MD5 小写十六进制,与 node_core tokenService.getMd5 一致)
-- =============================================================================
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `sys_log`;
DROP TABLE IF EXISTS `sys_user`;
DROP TABLE IF EXISTS `sys_menu`;
DROP TABLE IF EXISTS `sys_role`;
DROP TABLE IF EXISTS `sys_parameter`;
DROP TABLE IF EXISTS `sys_tenant`;
CREATE TABLE `sys_tenant` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '租户名称',
`code` varchar(64) NOT NULL DEFAULT '' COMMENT '租户编码(登录 tenant_code',
`remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
`status` int NOT NULL DEFAULT 1 COMMENT '1启用 0停用',
`is_platform` int NOT NULL DEFAULT 0 COMMENT '1平台租户',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_sys_tenant_code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='租户';
CREATE TABLE `sys_role` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '角色名称',
`type` int NOT NULL DEFAULT 0 COMMENT '0普通 1系统',
`menus` json DEFAULT NULL COMMENT '权限菜单id数组等',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色';
CREATE TABLE `sys_user` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '登录名',
`password` varchar(100) NOT NULL DEFAULT '' COMMENT 'MD5密码',
`roleId` int NOT NULL COMMENT '角色id',
`tenant_id` int NOT NULL DEFAULT 1 COMMENT '租户id',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `idx_sys_user_tenant` (`tenant_id`),
KEY `idx_sys_user_role` (`roleId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户';
CREATE TABLE `sys_menu` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '菜单名称',
`parent_id` int unsigned DEFAULT 0 COMMENT '父id',
`icon` varchar(100) NOT NULL DEFAULT '' COMMENT '图标',
`path` varchar(255) NOT NULL DEFAULT '' COMMENT '路径',
`type` varchar(255) NOT NULL DEFAULT '页面' COMMENT '菜单/页面/外链/功能',
`model_id` int unsigned DEFAULT 0 COMMENT '模型id',
`form_id` int unsigned DEFAULT 0 COMMENT '表单id',
`component` varchar(100) NOT NULL DEFAULT '' COMMENT '组件地址',
`api_path` varchar(100) NOT NULL DEFAULT '' COMMENT 'api地址',
`is_show_menu` int NOT NULL DEFAULT 1 COMMENT '是否显示在菜单',
`is_show` int NOT NULL DEFAULT 1 COMMENT '是否展示',
`sort` int NOT NULL DEFAULT 0 COMMENT '排序',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `idx_sys_menu_parent` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='菜单';
CREATE TABLE `sys_parameter` (
`id` int NOT NULL AUTO_INCREMENT,
`key` varchar(100) NOT NULL DEFAULT '' COMMENT '参数key',
`value` varchar(500) NOT NULL DEFAULT '' COMMENT '',
`remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
`is_modified` int NOT NULL DEFAULT 0 COMMENT '0允许修改 1不允许',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_sys_parameter_key` (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统参数';
CREATE TABLE `sys_log` (
`id` int NOT NULL AUTO_INCREMENT,
`table_name` varchar(100) NOT NULL DEFAULT '' COMMENT '表名',
`operate` varchar(100) NOT NULL DEFAULT '' COMMENT '操作',
`content` json DEFAULT NULL COMMENT '内容',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_modify_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_delete` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='操作日志';
SET FOREIGN_KEY_CHECKS = 1;
INSERT INTO `sys_tenant` (`id`, `name`, `code`, `remark`, `status`, `is_platform`, `is_delete`)
VALUES (1, '默认平台租户', 'default', '初始化数据', 1, 1, 0);
INSERT INTO `sys_role` (`id`, `name`, `type`, `menus`, `is_delete`)
VALUES (1, '超级管理员', 1, CAST('[]' AS JSON), 0);
INSERT INTO `sys_user` (`id`, `name`, `password`, `roleId`, `tenant_id`, `is_delete`)
VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, 1, 0);
INSERT INTO `sys_parameter` (`key`, `value`, `remark`, `is_modified`, `is_delete`) VALUES
('sys_title', '管理系统', '登录页与顶栏标题', 0, 0),
('sys_logo', '', '顶栏 Logo 图片地址,可填上传后的相对路径', 0, 0);
INSERT INTO `sys_menu` (`id`, `name`, `parent_id`, `icon`, `path`, `type`, `model_id`, `form_id`, `component`, `api_path`, `is_show_menu`, `is_show`, `sort`, `is_delete`) VALUES
(1, '首页', 0, 'md-home', '/home', '页面', 0, 0, 'home/index', '', 1, 1, 1, 0),
(5, '系统管理', 0, 'md-settings', '/system', '菜单', 0, 0, '', '', 1, 1, 2, 0),
(11, '用户管理', 5, 'md-person', '/system/user', '页面', 0, 0, 'system/sys_user', '', 1, 1, 1, 0),
(12, '角色管理', 5, 'md-people', '/system/role', '页面', 0, 0, 'system/sys_role', '', 1, 1, 2, 0),
(13, '系统日志', 5, 'md-list', '/system/log', '页面', 0, 0, 'system/sys_log', '', 1, 1, 3, 0),
(15, '参数设置', 5, 'md-options', '/system/param', '页面', 0, 0, 'system/sys_param_setup', '', 1, 1, 4, 0),
(120, '高级管理', 0, 'md-construct', '/system', '菜单', 0, 0, '', '', 1, 1, 3, 0),
(122, '菜单管理', 120, 'md-menu', '/system/menu', '页面', 0, 0, 'system/sys_menu', '', 1, 1, 1, 0),
(124, '系统标题', 120, 'md-text', '/system/title', '页面', 0, 0, 'system/sys_title', '', 1, 1, 2, 0),
(125, '租户管理', 120, 'md-git-branch', '/system/tenant', '页面', 0, 0, 'system/sys_tenant', '', 1, 1, 3, 0);