-- 修改关于STS表结构，从单条记录改为多条记录

-- 1. 备份现有数据
CREATE TABLE IF NOT EXISTS `sys_about_sts_backup` AS SELECT * FROM `sys_about_sts`;

-- 2. 修改表结构，添加title和content字段
ALTER TABLE `sys_about_sts` ADD COLUMN `title` varchar(200) DEFAULT NULL COMMENT '标题' AFTER `id`;
ALTER TABLE `sys_about_sts` ADD COLUMN `content` longtext COMMENT '内容（富文本）' AFTER `title`;
ALTER TABLE `sys_about_sts` ADD COLUMN `sort_order` int(11) DEFAULT 0 COMMENT '排序顺序' AFTER `content`;

-- 3. 将单条记录拆分为多条记录
-- 插入从title1和content1转换的数据
INSERT INTO `sys_about_sts` (`title`, `content`, `sort_order`, `create_time`, `update_time`, `create_by`, `update_by`, `remark`)
SELECT `title1`, `content1`, 1, NOW(), NOW(), 'admin', 'admin', '从title1转换'
FROM `sys_about_sts` WHERE `id` = 1 AND `title1` IS NOT NULL AND `title1` != '';

-- 插入从title2和content2转换的数据
INSERT INTO `sys_about_sts` (`title`, `content`, `sort_order`, `create_time`, `update_time`, `create_by`, `update_by`, `remark`)
SELECT `title2`, `content2`, 2, NOW(), NOW(), 'admin', 'admin', '从title2转换'
FROM `sys_about_sts` WHERE `id` = 1 AND `title2` IS NOT NULL AND `title2` != '';

-- 插入从title3和content3转换的数据
INSERT INTO `sys_about_sts` (`title`, `content`, `sort_order`, `create_time`, `update_time`, `create_by`, `update_by`, `remark`)
SELECT `title3`, `content3`, 3, NOW(), NOW(), 'admin', 'admin', '从title3转换'
FROM `sys_about_sts` WHERE `id` = 1 AND `title3` IS NOT NULL AND `title3` != '';

-- 插入从title4和content4转换的数据
INSERT INTO `sys_about_sts` (`title`, `content`, `sort_order`, `create_time`, `update_time`, `create_by`, `update_by`, `remark`)
SELECT `title4`, `content4`, 4, NOW(), NOW(), 'admin', 'admin', '从title4转换'
FROM `sys_about_sts` WHERE `id` = 1 AND `title4` IS NOT NULL AND `title4` != '';

-- 4. 删除原始的单条记录（id=1）
DELETE FROM `sys_about_sts` WHERE `id` = 1;

-- 5. 删除旧的字段
ALTER TABLE `sys_about_sts` DROP COLUMN `title1`;
ALTER TABLE `sys_about_sts` DROP COLUMN `content1`;
ALTER TABLE `sys_about_sts` DROP COLUMN `title2`;
ALTER TABLE `sys_about_sts` DROP COLUMN `content2`;
ALTER TABLE `sys_about_sts` DROP COLUMN `title3`;
ALTER TABLE `sys_about_sts` DROP COLUMN `content3`;
ALTER TABLE `sys_about_sts` DROP COLUMN `title4`;
ALTER TABLE `sys_about_sts` DROP COLUMN `content4`;
