yunzer_go/server/sql/dict_tables.sql
2025-11-07 17:38:59 +08:00

46 lines
2.9 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.

-- 字典类型表
CREATE TABLE IF NOT EXISTS `sys_dict_type` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`tenant_id` int(11) NOT NULL DEFAULT '0' COMMENT '租户ID0表示平台字典>0表示租户字典',
`dict_code` varchar(50) NOT NULL COMMENT '字典编码(唯一,如 USER_STATUS',
`dict_name` varchar(100) NOT NULL COMMENT '字典名称(如 用户状态)',
`parent_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '父级字典ID0表示一级字典',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态0-禁用1-启用)',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序号',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除0-未删1-已删)',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_dict_code_tenant` (`dict_code`, `is_deleted`),
KEY `idx_parent_id` (`parent_id`, `is_deleted`),
KEY `idx_status` (`status`, `is_deleted`),
KEY `idx_tenant_id` (`tenant_id`, `is_deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典类型表';
-- 字典项表
CREATE TABLE IF NOT EXISTS `sys_dict_item` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`dict_type_id` bigint(20) NOT NULL COMMENT '字典类型ID',
`dict_label` varchar(100) NOT NULL COMMENT '字典标签(显示值,如 正常)',
`dict_value` varchar(100) NOT NULL COMMENT '字典值(存储值,如 1',
`parent_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '父级字典项ID0表示一级项',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态0-禁用1-启用)',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序号',
`color` varchar(20) DEFAULT NULL COMMENT '颜色标记(如 #1890ff',
`icon` varchar(50) DEFAULT NULL COMMENT '图标(如 el-icon-success',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除0-未删1-已删)',
PRIMARY KEY (`id`),
KEY `idx_dict_type_parent_status` (`dict_type_id`, `parent_id`, `status`, `is_deleted`),
UNIQUE KEY `uk_dict_type_value` (`dict_type_id`, `dict_value`, `is_deleted`),
KEY `idx_parent_id` (`parent_id`, `status`, `is_deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典项表';