Files
wuhan-saga/database/sql/migration_news_multisite.sql
王文昊 3daa0273a4 feat(news): 支持新闻中心多站点隔离功能
新增站点编码配置,支持新闻分类与文章按站点隔离。主要变更包括:
- 数据库表增加 site_code 字段及索引
- 后台管理界面支持按站点筛选
- 前台接口支持通过查询参数或请求头指定站点
- 新增站点配置与解析逻辑
2026-05-05 15:09:49 +08:00

38 lines
2.2 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.

-- =============================================================================
-- 新闻中心多站点:为 f_news / f_news_category 增加 site_code
-- 执行前请备份数据库。可与 schema 增量部署,适合在 Gitea 发版后由运维一次性执行。
-- 固定站点编码示例wuhansaga主站、saga-secondary第二站点可按品牌改名
-- =============================================================================
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
-- 新闻分类:站点维度的栏目互相独立(不同站点可有各自一套分类及排序)
ALTER TABLE f_news_category
ADD COLUMN site_code VARCHAR(32) NOT NULL DEFAULT 'wuhansaga'
COMMENT '站点编码:小写英文短码,如 wuhansaga、saga-secondary扩展新站时仅增编码不改结构'
AFTER category_id;
ALTER TABLE f_news_category
ADD KEY idx_f_news_category_site (site_code, del_flag, is_published, sort_order);
-- 新闻正文:与分类 site_code 逻辑上一致;保存时业务侧校验 category 与 news 同属一站
ALTER TABLE f_news
ADD COLUMN site_code VARCHAR(32) NOT NULL DEFAULT 'wuhansaga'
COMMENT '站点编码,与 f_news_category.site_code 取值域一致'
AFTER category_id;
ALTER TABLE f_news
ADD KEY idx_f_news_site_list (site_code, del_flag, is_published, category_id),
ADD KEY idx_f_news_site_time (site_code, del_flag, is_published, create_time);
-- 旧数据:全部归入主站(若第二站需相同栏目结构,可复制分类再批量改 site_code / 或导数据)
UPDATE f_news_category SET site_code = 'wuhansaga' WHERE site_code = '' OR site_code IS NULL;
UPDATE f_news SET site_code = 'wuhansaga' WHERE site_code = '' OR site_code IS NULL;
-- ---------------------------------------------------------------------------
-- 【可选】第二站点初始化分类骨架(与主站相同名称时仍需独立 category_id
-- ---------------------------------------------------------------------------
-- INSERT INTO f_news_category (site_code, name_zh, name_en, sort_order, is_published)
-- SELECT 'saga-secondary', name_zh, name_en, sort_order, is_published
-- FROM f_news_category WHERE site_code = 'wuhansaga' AND del_flag = 0;