-- ============================================================ -- addon/articles/install.sql —— 文章CMS插件数据表 -- 框架约定:插件安装时由 ywxapp\service\AddonService 执行本文件 -- (仅允许 CREATE TABLE / INSERT,见 importsql 白名单)。 -- 表名须为 __PREFIX__articles_*,与插件名一致。 -- 时间字段统一:create_at / update_at / delete_at(int 时间戳,0=未删) -- ============================================================ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; CREATE TABLE IF NOT EXISTS `__PREFIX__articles_article` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL DEFAULT '' COMMENT '标题', `content` longtext NOT NULL COMMENT '正文', `summary` varchar(500) DEFAULT '' COMMENT '摘要', `cover_image` varchar(255) DEFAULT '' COMMENT '封面图', `uid` int NOT NULL DEFAULT 0 COMMENT '作者ID(member_user.uid)', `author` varchar(50) DEFAULT '' COMMENT '作者名(冗余)', `cid` int NOT NULL DEFAULT 0 COMMENT '分类ID', `status` tinyint(1) DEFAULT 1 COMMENT '状态:1发布 0草稿', `is_top` tinyint(1) DEFAULT 0 COMMENT '是否置顶', `is_recommend` tinyint(1) DEFAULT 0 COMMENT '是否推荐', `view_count` int DEFAULT 0 COMMENT '浏览次数', `comment_count` int DEFAULT 0 COMMENT '评论数', `like_count` int DEFAULT 0 COMMENT '点赞数', `create_at` int NOT NULL DEFAULT 0 COMMENT '创建时间', `update_at` int NOT NULL DEFAULT 0 COMMENT '更新时间', `delete_at` int NOT NULL DEFAULT 0 COMMENT '删除时间', PRIMARY KEY (`id`), KEY `idx_uid` (`uid`), KEY `idx_cid` (`cid`), KEY `idx_status_create` (`status`,`create_at`), KEY `idx_delete` (`delete_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章表'; CREATE TABLE IF NOT EXISTS `__PREFIX__articles_category` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '' COMMENT '分类名称', `alias` varchar(50) NOT NULL DEFAULT '' COMMENT '分类别名(URL标识)', `description` varchar(255) DEFAULT '' COMMENT '分类描述', `cover` varchar(255) DEFAULT '' COMMENT '分类封面', `sort` int DEFAULT 0 COMMENT '排序权重', `status` tinyint(1) DEFAULT 1 COMMENT '状态', `create_at` int NOT NULL DEFAULT 0 COMMENT '创建时间', `update_at` int NOT NULL DEFAULT 0 COMMENT '更新时间', `delete_at` int NOT NULL DEFAULT 0 COMMENT '删除时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_alias` (`alias`), KEY `idx_delete` (`delete_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章分类表'; CREATE TABLE IF NOT EXISTS `__PREFIX__articles_tag` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '' COMMENT '标签名称', `alias` varchar(50) NOT NULL DEFAULT '' COMMENT '标签别名', `description` varchar(255) DEFAULT '' COMMENT '标签描述', `create_at` int NOT NULL DEFAULT 0 COMMENT '创建时间', `update_at` int NOT NULL DEFAULT 0 COMMENT '更新时间', `delete_at` int NOT NULL DEFAULT 0 COMMENT '删除时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_name` (`name`), KEY `idx_delete` (`delete_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章标签表'; CREATE TABLE IF NOT EXISTS `__PREFIX__articles_article_tag` ( `aid` int NOT NULL COMMENT '文章ID', `tid` int NOT NULL COMMENT '标签ID', PRIMARY KEY (`aid`,`tid`) USING BTREE, KEY `idx_tid` (`tid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章标签关联表'; CREATE TABLE IF NOT EXISTS `__PREFIX__articles_comment` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `uid` int NOT NULL DEFAULT 0 COMMENT '用户ID(member_user.uid)', `aid` int NOT NULL DEFAULT 0 COMMENT '文章ID', `pid` int NOT NULL DEFAULT 0 COMMENT '父评论ID', `content` text NOT NULL COMMENT '评论内容', `status` tinyint(1) DEFAULT 1 COMMENT '状态:1正常 0待审核', `like_count` int DEFAULT 0 COMMENT '点赞数', `ip` varchar(45) DEFAULT '' COMMENT 'IP地址', `user_agent` varchar(255) DEFAULT '' COMMENT '用户代理', `create_at` int NOT NULL DEFAULT 0 COMMENT '创建时间', `update_at` int NOT NULL DEFAULT 0 COMMENT '更新时间', `delete_at` int NOT NULL DEFAULT 0 COMMENT '删除时间', PRIMARY KEY (`id`), KEY `idx_aid` (`aid`), KEY `idx_pid` (`pid`), KEY `idx_delete` (`delete_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章评论表'; SET FOREIGN_KEY_CHECKS = 1;