-- ============================================================
-- addon/seo/install.sql  —— SEO增强插件数据表
-- 框架约定：插件安装时由 ywxapp\service\AddonService 执行本文件
--           （仅允许 CREATE TABLE / INSERT，见 importsql 白名单）。
-- 表名须为 __PREFIX__seo_*，与 __PREFIX__addon 等核心表命名一致。
-- 注意：种子文案禁用 --（框架会逐行把 -- 起内容当注释删，会砍断字符串）。
-- ============================================================
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

CREATE TABLE IF NOT EXISTS `__PREFIX__seo_config` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '变量名',
  `group` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '分组',
  `title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '变量标题',
  `tip` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '变量描述',
  `type` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '类型:string,text,int,bool',
  `value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '变量值',
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '变量字典数据',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SEO配置表';

INSERT INTO `__PREFIX__seo_config` (`id`, `name`, `group`, `title`, `tip`, `type`, `value`) VALUES
  (1, 'site_title', 'basic', '站点标题模板', '支持变量替换', 'string', '{title} - {name}'),
  (2, 'site_keywords', 'basic', '默认关键词', '逗号分隔', 'string', ''),
  (3, 'site_description', 'basic', '默认描述', '首页描述', 'text', ''),
  (4, 'robots', 'basic', 'robots内容', '留空使用默认', 'text', 'User-agent: * Allow: /');

CREATE TABLE IF NOT EXISTS `__PREFIX__seo_keywords` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `keyword` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '关键词',
  `url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '内链目标URL',
  `weight` int DEFAULT '0' COMMENT '权重，越大越优先',
  `status` tinyint DEFAULT '1' COMMENT '状态：1-启用，0-禁用',
  `create_at` int DEFAULT NULL COMMENT '创建时间',
  `update_at` int DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_status` (`status`),
  KEY `idx_keyword` (`keyword`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='内链关键词表';

CREATE TABLE IF NOT EXISTS `__PREFIX__seo_snapshots` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `engine` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '搜索引擎：baidu/google/360/sogou',
  `url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '被统计页面URL',
  `indexed` tinyint DEFAULT '0' COMMENT '是否被收录：1-是，0-否',
  `rank` int DEFAULT '0' COMMENT '排名，0=未进入前100',
  `snapshot_date` date DEFAULT NULL COMMENT '快照日期',
  `create_at` int DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY `idx_engine` (`engine`),
  KEY `idx_date` (`snapshot_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='收录排名快照表';
