-- ============================================================
-- 卡片画布方案表（15 套预设由后台 init-presets 灌 layers JSON）
-- ============================================================

SET @db := DATABASE();
SET @exists := (
    SELECT COUNT(*) FROM information_schema.TABLES
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'cc_wx_card_scheme'
);
SET @sql := IF(@exists = 0,
    'CREATE TABLE `cc_wx_card_scheme` (
        `id` int unsigned NOT NULL AUTO_INCREMENT,
        `name` varchar(50) NOT NULL DEFAULT '''' COMMENT ''方案名'',
        `code` varchar(50) NOT NULL DEFAULT '''' COMMENT ''方案标识'',
        `preview` varchar(500) NOT NULL DEFAULT '''' COMMENT ''缩略图'',
        `layers` mediumtext COMMENT ''图层 JSON'',
        `is_preset` tinyint NOT NULL DEFAULT 0 COMMENT ''1=内置预设，不可删'',
        `app_code` varchar(20) NOT NULL DEFAULT '''' COMMENT ''品牌，空=通用'',
        `sort` int NOT NULL DEFAULT 0,
        `status` tinyint NOT NULL DEFAULT 0 COMMENT ''0=启用 1=停用'',
        `created_at` int NOT NULL DEFAULT 0,
        `updated_at` int NOT NULL DEFAULT 0,
        `deleted_at` int NOT NULL DEFAULT 0,
        PRIMARY KEY (`id`),
        UNIQUE KEY `uk_wx_card_scheme_code` (`code`, `app_code`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=''小程序卡片画布方案''',
    'SELECT ''skip cc_wx_card_scheme'' AS msg'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
