duidui_fiber/docs/migrations/add_doc_tables.sql
2026-03-27 10:34:03 +08:00

30 lines
1.8 KiB
SQL
Raw Permalink 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.

-- 文档管理:两层结构(文件夹 + 文件)
-- 执行: mysql -u root -p duidui_db < docs/migrations/add_doc_tables.sql
--
-- 使用文档管理功能前,需在权限表中增加 document:manage或在管理后台权限管理里新增
-- 并为相应角色勾选该权限;超级管理员无需配置即可访问。
-- 文件夹表(仅一层,无 parent_id
CREATE TABLE IF NOT EXISTS doc_folders (
id VARCHAR(64) NOT NULL PRIMARY KEY COMMENT '主键',
name VARCHAR(128) NOT NULL COMMENT '文件夹名称',
sort_order INT NOT NULL DEFAULT 0 COMMENT '排序(升序)',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='文档文件夹';
-- 文档表(属于某个文件夹)
CREATE TABLE IF NOT EXISTS doc_files (
id VARCHAR(64) NOT NULL PRIMARY KEY COMMENT '主键',
folder_id VARCHAR(64) NOT NULL COMMENT '所属文件夹 id',
name VARCHAR(256) NOT NULL COMMENT '显示名称',
file_name VARCHAR(256) NOT NULL DEFAULT '' COMMENT '原始文件名',
file_url VARCHAR(1024) NOT NULL COMMENT '文件访问 URLOSS 或相对路径)',
file_size BIGINT NOT NULL DEFAULT 0 COMMENT '文件大小(字节)',
mime_type VARCHAR(128) NOT NULL DEFAULT '' COMMENT 'MIME 类型,如 application/pdf',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_folder_id (folder_id),
KEY idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='文档文件';