migrate_course_sys/1781687994_create_course.up.sql
2026-06-18 11:13:32 +08:00

29 lines
1.1 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.

CREATE TABLE `course` (
`id` INT PRIMARY KEY AUTO_INCREMENT COMMENT '月度课程ID',
`series_id` INT NOT NULL COMMENT '所属系列ID',
-- 时间标识
`year` INT NOT NULL COMMENT '开课年份如2026',
`month` TINYINT NOT NULL COMMENT '几月1~12例如 3 表示3月份',
-- 课程信息
`title` VARCHAR(255) NOT NULL COMMENT '月度课程名称',
`description` TEXT COMMENT '月度课程简介',
`cover_image` VARCHAR(500) COMMENT '月度课程封面',
-- 价格与售卖
`price` DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT '售价(元)',
`original_price` DECIMAL(10, 2) COMMENT '原价/划线价',
`is_published` TINYINT DEFAULT 1 COMMENT '是否上架1-下架 2-上架',
-- 时间戳
`created_at` TIMESTAMP NULL DEFAULT NULL COMMENT '创建时间',
`updated_at` TIMESTAMP NULL DEFAULT NULL COMMENT '更新时间',
FOREIGN KEY (`series_id`) REFERENCES `course_series` (`id`) ON DELETE CASCADE,
-- 唯一约束:同一系列同一年同一月份只能有一条记录
UNIQUE KEY `uk_series_year_month` (`series_id`, `year`, `month`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='月度课程表';