Files
2026-07-30 17:33:08 +08:00

43 lines
2.5 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.
-- ============================================================
-- 04_news.sql
-- 新闻管理:文章 CRUD、相关推荐
-- 对应 proposal.md 第 5 节
-- ============================================================
-- -----------------------------------------------------------
-- 5.1 新闻文章
-- -----------------------------------------------------------
CREATE TABLE IF NOT EXISTS `www_news_articles` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`title_zh` VARCHAR(200) NOT NULL COMMENT '文章标题(中文)',
`title_en` VARCHAR(200) NOT NULL COMMENT '文章标题(英文)',
`slug` VARCHAR(200) NOT NULL COMMENT 'URL 路径标识,如 new-product-launch',
`summary_zh` VARCHAR(300) NOT NULL DEFAULT '' COMMENT '文章摘要(中文,≤100字)',
`summary_en` VARCHAR(300) NOT NULL DEFAULT '' COMMENT '文章摘要(英文)',
`cover_url` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '封面图路径(16:9',
`content_zh` MEDIUMTEXT COMMENT '正文内容(中文,富文本)',
`content_en` MEDIUMTEXT COMMENT '正文内容(英文,富文本)',
`status` VARCHAR(20) NOT NULL DEFAULT 'draft' COMMENT '发布状态: draft / published / offline',
`published_at` DATETIME DEFAULT NULL COMMENT '发布时间(可为未来时间,定时发布)',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_slug` (`slug`),
KEY `idx_status` (`status`, `published_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='新闻文章';
-- -----------------------------------------------------------
-- 5.2 文章相关推荐(手动指定,最多 3 篇)
-- -----------------------------------------------------------
CREATE TABLE IF NOT EXISTS `www_news_recommendations` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`article_id` BIGINT UNSIGNED NOT NULL COMMENT '文章 ID',
`recommended_id` BIGINT UNSIGNED NOT NULL COMMENT '推荐文章 ID',
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '推荐排序',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_article_recommended` (`article_id`, `recommended_id`),
KEY `idx_article` (`article_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='文章手动推荐关联';