CREATE TABLE `math_point` ( `id` bigint AUTO_INCREMENT NOT NULL, `point_id` varchar(191) NOT NULL, `module` varchar(20) NOT NULL, `module_name` varchar(50) NOT NULL, `title` varchar(200) NOT NULL, `grade` varchar(30), `difficulty` int NOT NULL DEFAULT 1, `summary` text, `md` text NOT NULL, `seq` int NOT NULL, `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT `math_point_id` PRIMARY KEY(`id`), CONSTRAINT `uq_math_point_id` UNIQUE(`point_id`) ); --> statement-breakpoint CREATE TABLE `math_progress` ( `id` bigint AUTO_INCREMENT NOT NULL, `child_user_id` bigint NOT NULL, `point_id` varchar(191) NOT NULL, `score` int, `passed` boolean NOT NULL DEFAULT false, `completed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT `math_progress_id` PRIMARY KEY(`id`), CONSTRAINT `uq_math_child_point` UNIQUE(`child_user_id`,`point_id`) ); --> statement-breakpoint ALTER TABLE `math_progress` ADD CONSTRAINT `math_progress_child_user_id_user_id_fk` FOREIGN KEY (`child_user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action; --> statement-breakpoint CREATE TABLE `math_weekly_test` ( `id` bigint AUTO_INCREMENT NOT NULL, `child_user_id` bigint NOT NULL, `week_key` varchar(12) NOT NULL, `score` int, `correct` int, `total` int, `passed` boolean NOT NULL DEFAULT false, `questions` text, `taken_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT `math_weekly_test_id` PRIMARY KEY(`id`), CONSTRAINT `uq_math_weekly_child_week` UNIQUE(`child_user_id`,`week_key`) ); --> statement-breakpoint ALTER TABLE `math_weekly_test` ADD CONSTRAINT `math_weekly_test_child_user_id_user_id_fk` FOREIGN KEY (`child_user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action; --> statement-breakpoint CREATE TABLE `exam_paper` ( `id` bigint AUTO_INCREMENT NOT NULL, `paper_id` varchar(191) NOT NULL, `subject` varchar(20) NOT NULL DEFAULT 'math', `grade` varchar(20) NOT NULL, `semester` varchar(10) NOT NULL, `month` int NOT NULL, `exam_type` varchar(20) NOT NULL, `title` varchar(300) NOT NULL, `region` varchar(60), `year` int, `duration` int, `full_score` int, `source_url` varchar(500), `summary` text, `questions` text NOT NULL, `seq` int NOT NULL, `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT `exam_paper_id` PRIMARY KEY(`id`), CONSTRAINT `uq_exam_paper_id` UNIQUE(`paper_id`) ); --> statement-breakpoint CREATE INDEX `idx_exam_paper_scope` ON `exam_paper` (`subject`,`grade`,`semester`,`month`); --> statement-breakpoint CREATE TABLE `exam_record` ( `id` bigint AUTO_INCREMENT NOT NULL, `child_user_id` bigint NOT NULL, `paper_id` varchar(191) NOT NULL, `score` int, `correct` int, `total` int, `passed` boolean NOT NULL DEFAULT false, `answers` text, `taken_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT `exam_record_id` PRIMARY KEY(`id`), CONSTRAINT `uq_exam_child_paper` UNIQUE(`child_user_id`,`paper_id`) ); --> statement-breakpoint ALTER TABLE `exam_record` ADD CONSTRAINT `exam_record_child_user_id_user_id_fk` FOREIGN KEY (`child_user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;