-- 008 编辑模式扩展：为 news / cases / categories 表增加 mode 字段
-- 用途：后台新闻、客户案例、分类编辑支持「固定版面 fixed / 可视化编辑 builder」两种模式（与产品/单页一致）
-- 幂等：用 information_schema 判断列是否存在，存在则跳过（兼容 MySQL 5.7 / 8.x 全版本及 MariaDB）
-- 旧数据默认 'fixed'，渲染行为不变；已用可视化编辑器存过 layout 的记录可手动置为 'builder'
-- 应用方式：后台「系统 / 数据库升级」→ 找到本文件 → 点「升级」

SET @db = DATABASE();

-- news
SET @has = (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'news' AND COLUMN_NAME = 'mode');
SET @sql = IF(@has = 0, 'ALTER TABLE `news` ADD COLUMN `mode` VARCHAR(16) NOT NULL DEFAULT \'fixed\' AFTER `layout`', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

-- cases
SET @has = (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'cases' AND COLUMN_NAME = 'mode');
SET @sql = IF(@has = 0, 'ALTER TABLE `cases` ADD COLUMN `mode` VARCHAR(16) NOT NULL DEFAULT \'fixed\' AFTER `layout`', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

-- categories
SET @has = (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'categories' AND COLUMN_NAME = 'mode');
SET @sql = IF(@has = 0, 'ALTER TABLE `categories` ADD COLUMN `mode` VARCHAR(16) NOT NULL DEFAULT \'fixed\' AFTER `layout`', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
