feat(drizzle): consolidate database migrations into single baseline
- Remove 0000-0021 incremental migrations - Add consolidated 0000_aberrant_deathstrike.sql baseline - Update meta/_journal.json and 0000_snapshot.json
This commit is contained in:
1560
drizzle/0000_aberrant_deathstrike.sql
Normal file
1560
drizzle/0000_aberrant_deathstrike.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,816 +0,0 @@
|
||||
CREATE TABLE `academic_years` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`start_date` timestamp NOT NULL,
|
||||
`end_date` timestamp NOT NULL,
|
||||
`is_active` boolean NOT NULL DEFAULT false,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `academic_years_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `academic_years_name_unique` UNIQUE(`name`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `accounts` (
|
||||
`userId` varchar(128) NOT NULL,
|
||||
`type` varchar(255) NOT NULL,
|
||||
`provider` varchar(255) NOT NULL,
|
||||
`providerAccountId` varchar(255) NOT NULL,
|
||||
`refresh_token` text,
|
||||
`access_token` text,
|
||||
`expires_at` int,
|
||||
`token_type` varchar(255),
|
||||
`scope` varchar(255),
|
||||
`id_token` text,
|
||||
`session_state` varchar(255),
|
||||
CONSTRAINT `accounts_provider_providerAccountId_pk` PRIMARY KEY(`provider`,`providerAccountId`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `ai_providers` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`provider` enum('zhipu','openai','gemini','custom') NOT NULL,
|
||||
`base_url` varchar(512),
|
||||
`model` varchar(128) NOT NULL,
|
||||
`api_key_encrypted` text NOT NULL,
|
||||
`api_key_last4` varchar(4),
|
||||
`is_default` boolean NOT NULL DEFAULT false,
|
||||
`created_by` varchar(128),
|
||||
`updated_by` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `ai_providers_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `announcements` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`type` enum('school','grade','class') NOT NULL DEFAULT 'school',
|
||||
`status` enum('draft','published','archived') NOT NULL DEFAULT 'draft',
|
||||
`target_grade_id` varchar(128),
|
||||
`target_class_id` varchar(128),
|
||||
`author_id` varchar(128) NOT NULL,
|
||||
`published_at` datetime,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `announcements_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `attendance_records` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`schedule_id` varchar(128),
|
||||
`date` date NOT NULL,
|
||||
`status` enum('present','absent','late','early_leave','excused') NOT NULL,
|
||||
`remark` text,
|
||||
`recorded_by` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `attendance_records_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `attendance_rules` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128),
|
||||
`late_threshold_minutes` int DEFAULT 15,
|
||||
`early_leave_threshold_minutes` int DEFAULT 15,
|
||||
`enable_auto_mark` boolean DEFAULT false,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `attendance_rules_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `audit_logs` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`user_name` varchar(255) NOT NULL,
|
||||
`action` varchar(255) NOT NULL,
|
||||
`module` varchar(128) NOT NULL,
|
||||
`target_id` varchar(128),
|
||||
`target_type` varchar(128),
|
||||
`detail` text,
|
||||
`ip_address` varchar(45),
|
||||
`user_agent` varchar(512),
|
||||
`status` enum('success','failure') NOT NULL DEFAULT 'success',
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `audit_logs_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `chapters` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`textbook_id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`order` int DEFAULT 0,
|
||||
`parent_id` varchar(128),
|
||||
`content` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `chapters_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `class_enrollments` (
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`class_enrollment_status` enum('active','inactive') NOT NULL DEFAULT 'active',
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `class_enrollments_class_id_student_id_pk` PRIMARY KEY(`class_id`,`student_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `class_schedule` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`weekday` int NOT NULL,
|
||||
`start_time` varchar(5) NOT NULL,
|
||||
`end_time` varchar(5) NOT NULL,
|
||||
`course` varchar(255) NOT NULL,
|
||||
`location` varchar(100),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `class_schedule_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `class_subject_teachers` (
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`subject_id` varchar(128) NOT NULL,
|
||||
`teacher_id` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `class_subject_teachers_class_id_subject_id_pk` PRIMARY KEY(`class_id`,`subject_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `classes` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`school_name` varchar(255),
|
||||
`school_id` varchar(128),
|
||||
`name` varchar(255) NOT NULL,
|
||||
`grade` varchar(50) NOT NULL,
|
||||
`grade_id` varchar(128),
|
||||
`homeroom` varchar(50),
|
||||
`room` varchar(50),
|
||||
`invitation_code` varchar(6),
|
||||
`teacher_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `classes_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `classes_invitation_code_unique` UNIQUE(`invitation_code`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `classrooms` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`building` varchar(100),
|
||||
`floor` int,
|
||||
`capacity` int,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `classrooms_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `classrooms_name_unique` UNIQUE(`name`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `course_plan_items` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`plan_id` varchar(128) NOT NULL,
|
||||
`week` int NOT NULL,
|
||||
`topic` varchar(255) NOT NULL,
|
||||
`content` text,
|
||||
`hours` int NOT NULL DEFAULT 2,
|
||||
`textbook_chapter` varchar(255),
|
||||
`notes` text,
|
||||
`is_completed` boolean NOT NULL DEFAULT false,
|
||||
`completed_at` date,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `course_plan_items_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `course_plans` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`subject_id` varchar(128) NOT NULL,
|
||||
`teacher_id` varchar(128) NOT NULL,
|
||||
`academic_year_id` varchar(128),
|
||||
`semester` enum('1','2') NOT NULL DEFAULT '1',
|
||||
`total_hours` int NOT NULL DEFAULT 0,
|
||||
`completed_hours` int NOT NULL DEFAULT 0,
|
||||
`weekly_hours` int NOT NULL DEFAULT 0,
|
||||
`start_date` date,
|
||||
`end_date` date,
|
||||
`syllabus` text,
|
||||
`objectives` text,
|
||||
`status` enum('planning','active','completed','paused') NOT NULL DEFAULT 'planning',
|
||||
`created_by` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `course_plans_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `data_change_logs` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`table_name` varchar(128) NOT NULL,
|
||||
`record_id` varchar(128) NOT NULL,
|
||||
`action` enum('create','update','delete') NOT NULL,
|
||||
`old_value` text,
|
||||
`new_value` text,
|
||||
`changed_by` varchar(128) NOT NULL,
|
||||
`changed_by_name` varchar(255) NOT NULL,
|
||||
`ip_address` varchar(45),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `data_change_logs_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `departments` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`description` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `departments_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `departments_name_unique` UNIQUE(`name`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exam_questions` (
|
||||
`exam_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`score` int DEFAULT 0,
|
||||
`order` int DEFAULT 0,
|
||||
CONSTRAINT `exam_questions_exam_id_question_id_pk` PRIMARY KEY(`exam_id`,`question_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exam_submissions` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`exam_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`score` int,
|
||||
`status` varchar(50) DEFAULT 'started',
|
||||
`submitted_at` timestamp,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `exam_submissions_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exams` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`description` text,
|
||||
`structure` json,
|
||||
`creator_id` varchar(128) NOT NULL,
|
||||
`subject_id` varchar(128),
|
||||
`grade_id` varchar(128),
|
||||
`start_time` timestamp,
|
||||
`end_time` timestamp,
|
||||
`status` varchar(50) DEFAULT 'draft',
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `exams_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `file_attachments` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`filename` varchar(255) NOT NULL,
|
||||
`original_name` varchar(255) NOT NULL,
|
||||
`mime_type` varchar(128) NOT NULL,
|
||||
`size` bigint NOT NULL,
|
||||
`storage_path` varchar(512) NOT NULL,
|
||||
`url` varchar(512),
|
||||
`uploader_id` varchar(128) NOT NULL,
|
||||
`target_type` varchar(128),
|
||||
`target_id` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `file_attachments_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `grade_records` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`subject_id` varchar(128) NOT NULL,
|
||||
`exam_id` varchar(128),
|
||||
`academic_year_id` varchar(128),
|
||||
`title` varchar(255) NOT NULL,
|
||||
`score` decimal(6,2) NOT NULL,
|
||||
`full_score` decimal(6,2) NOT NULL DEFAULT '100',
|
||||
`type` enum('exam','quiz','homework','other') NOT NULL DEFAULT 'exam',
|
||||
`semester` enum('1','2') NOT NULL DEFAULT '1',
|
||||
`recorded_by` varchar(128) NOT NULL,
|
||||
`remark` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `grade_records_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `grades` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`school_id` varchar(128) NOT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`order` int NOT NULL DEFAULT 0,
|
||||
`grade_head_id` varchar(128),
|
||||
`teaching_head_id` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `grades_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `homework_answers` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`submission_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`answer_content` json,
|
||||
`score` int,
|
||||
`feedback` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `homework_answers_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `homework_assignment_questions` (
|
||||
`assignment_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`score` int DEFAULT 0,
|
||||
`order` int DEFAULT 0,
|
||||
CONSTRAINT `homework_assignment_questions_assignment_id_question_id_pk` PRIMARY KEY(`assignment_id`,`question_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `homework_assignment_targets` (
|
||||
`assignment_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `homework_assignment_targets_assignment_id_student_id_pk` PRIMARY KEY(`assignment_id`,`student_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `homework_assignments` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`source_exam_id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`description` text,
|
||||
`structure` json,
|
||||
`status` varchar(50) DEFAULT 'draft',
|
||||
`creator_id` varchar(128) NOT NULL,
|
||||
`available_at` timestamp,
|
||||
`due_at` timestamp,
|
||||
`allow_late` boolean NOT NULL DEFAULT false,
|
||||
`late_due_at` timestamp,
|
||||
`max_attempts` int NOT NULL DEFAULT 1,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `homework_assignments_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `homework_submissions` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`assignment_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`attempt_no` int NOT NULL DEFAULT 1,
|
||||
`score` int,
|
||||
`status` varchar(50) DEFAULT 'started',
|
||||
`started_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`submitted_at` timestamp,
|
||||
`is_late` boolean NOT NULL DEFAULT false,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `homework_submissions_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `knowledge_points` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`description` text,
|
||||
`anchor_text` varchar(255),
|
||||
`parent_id` varchar(128),
|
||||
`chapter_id` varchar(128),
|
||||
`level` int DEFAULT 0,
|
||||
`order` int DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `knowledge_points_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `login_logs` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`user_id` varchar(128),
|
||||
`user_email` varchar(255) NOT NULL,
|
||||
`action` enum('signin','signout','signup') NOT NULL,
|
||||
`status` enum('success','failure') NOT NULL DEFAULT 'success',
|
||||
`ip_address` varchar(45),
|
||||
`user_agent` varchar(512),
|
||||
`error_message` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `login_logs_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `message_notifications` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`type` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`content` text,
|
||||
`link` varchar(512),
|
||||
`is_read` boolean NOT NULL DEFAULT false,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `message_notifications_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `messages` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`sender_id` varchar(128) NOT NULL,
|
||||
`receiver_id` varchar(128) NOT NULL,
|
||||
`subject` varchar(255),
|
||||
`content` text NOT NULL,
|
||||
`is_read` boolean NOT NULL DEFAULT false,
|
||||
`read_at` timestamp,
|
||||
`parent_message_id` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `messages_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `notification_preferences` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`email_enabled` boolean NOT NULL DEFAULT false,
|
||||
`sms_enabled` boolean NOT NULL DEFAULT false,
|
||||
`push_enabled` boolean NOT NULL DEFAULT true,
|
||||
`homework_notifications` boolean NOT NULL DEFAULT true,
|
||||
`grade_notifications` boolean NOT NULL DEFAULT true,
|
||||
`announcement_notifications` boolean NOT NULL DEFAULT true,
|
||||
`message_notifications` boolean NOT NULL DEFAULT true,
|
||||
`attendance_notifications` boolean NOT NULL DEFAULT true,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `notification_preferences_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `notification_preferences_user_id_unique` UNIQUE(`user_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `parent_student_relations` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`parent_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`relation` varchar(50),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `parent_student_relations_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `password_security` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`failed_login_attempts` int NOT NULL DEFAULT 0,
|
||||
`locked_until` timestamp,
|
||||
`password_changed_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`must_change_password` boolean NOT NULL DEFAULT false,
|
||||
`last_password_change` timestamp,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `password_security_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `password_security_user_id_unique` UNIQUE(`user_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `questions` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`content` json NOT NULL,
|
||||
`type` enum('single_choice','multiple_choice','text','judgment','composite') NOT NULL,
|
||||
`difficulty` int DEFAULT 1,
|
||||
`parent_id` varchar(128),
|
||||
`author_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `questions_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `questions_to_knowledge_points` (
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`knowledge_point_id` varchar(128) NOT NULL,
|
||||
CONSTRAINT `questions_to_knowledge_points_question_id_knowledge_point_id_pk` PRIMARY KEY(`question_id`,`knowledge_point_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `role_permissions` (
|
||||
`role_id` varchar(128) NOT NULL,
|
||||
`permission` varchar(100) NOT NULL,
|
||||
CONSTRAINT `role_permissions_role_id_permission_pk` PRIMARY KEY(`role_id`,`permission`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `roles` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`description` varchar(255),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `roles_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `roles_name_unique` UNIQUE(`name`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `schedule_changes` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`original_schedule_id` varchar(128),
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`original_teacher_id` varchar(128),
|
||||
`substitute_teacher_id` varchar(128),
|
||||
`original_date` date,
|
||||
`new_date` date,
|
||||
`new_start_time` varchar(10),
|
||||
`new_end_time` varchar(10),
|
||||
`reason` text,
|
||||
`status` enum('pending','approved','rejected','completed') NOT NULL DEFAULT 'pending',
|
||||
`requested_by` varchar(128) NOT NULL,
|
||||
`approved_by` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `schedule_changes_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `scheduling_rules` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128),
|
||||
`max_daily_hours` int DEFAULT 8,
|
||||
`max_continuous_hours` int DEFAULT 2,
|
||||
`lunch_break_start` varchar(10) DEFAULT '12:00',
|
||||
`lunch_break_end` varchar(10) DEFAULT '13:00',
|
||||
`morning_start` varchar(10) DEFAULT '08:00',
|
||||
`afternoon_end` varchar(10) DEFAULT '17:00',
|
||||
`avoid_back_to_back` boolean DEFAULT false,
|
||||
`balanced_subjects` boolean DEFAULT true,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `scheduling_rules_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `schools` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`code` varchar(50),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `schools_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `schools_name_unique` UNIQUE(`name`),
|
||||
CONSTRAINT `schools_code_unique` UNIQUE(`code`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `sessions` (
|
||||
`sessionToken` varchar(255) NOT NULL,
|
||||
`userId` varchar(128) NOT NULL,
|
||||
`expires` timestamp NOT NULL,
|
||||
CONSTRAINT `sessions_sessionToken` PRIMARY KEY(`sessionToken`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `subjects` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`code` varchar(50),
|
||||
`order` int DEFAULT 0,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `subjects_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `subjects_name_unique` UNIQUE(`name`),
|
||||
CONSTRAINT `subjects_code_unique` UNIQUE(`code`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `submission_answers` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`submission_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`answer_content` json,
|
||||
`score` int,
|
||||
`feedback` text,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `submission_answers_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `textbooks` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`subject` varchar(100) NOT NULL,
|
||||
`grade` varchar(50),
|
||||
`publisher` varchar(100),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `textbooks_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `users` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255),
|
||||
`email` varchar(255) NOT NULL,
|
||||
`emailVerified` timestamp,
|
||||
`image` varchar(255),
|
||||
`password` varchar(255),
|
||||
`phone` varchar(30),
|
||||
`address` varchar(255),
|
||||
`gender` varchar(20),
|
||||
`age` int,
|
||||
`grade_id` varchar(128),
|
||||
`department_id` varchar(128),
|
||||
`onboarded_at` timestamp,
|
||||
`birth_date` date,
|
||||
`guardian_name` varchar(255),
|
||||
`guardian_phone` varchar(20),
|
||||
`guardian_relation` varchar(50),
|
||||
`consent_accepted_at` datetime,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `users_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `users_email_unique` UNIQUE(`email`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `users_to_roles` (
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`role_id` varchar(128) NOT NULL,
|
||||
CONSTRAINT `users_to_roles_user_id_role_id_pk` PRIMARY KEY(`user_id`,`role_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `verificationTokens` (
|
||||
`identifier` varchar(255) NOT NULL,
|
||||
`token` varchar(255) NOT NULL,
|
||||
`expires` timestamp NOT NULL,
|
||||
CONSTRAINT `verificationTokens_identifier_token_pk` PRIMARY KEY(`identifier`,`token`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_userId_users_id_fk` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `announcements` ADD CONSTRAINT `announcements_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_records` ADD CONSTRAINT `attendance_records_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_records` ADD CONSTRAINT `attendance_records_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_records` ADD CONSTRAINT `attendance_records_recorded_by_users_id_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_records` ADD CONSTRAINT `ar_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_records` ADD CONSTRAINT `ar_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_records` ADD CONSTRAINT `ar_rb_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_rules` ADD CONSTRAINT `attendance_rules_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `attendance_rules` ADD CONSTRAINT `atr_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `chapters` ADD CONSTRAINT `chapters_textbook_id_textbooks_id_fk` FOREIGN KEY (`textbook_id`) REFERENCES `textbooks`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_enrollments` ADD CONSTRAINT `ce_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_enrollments` ADD CONSTRAINT `ce_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_schedule` ADD CONSTRAINT `cs_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `class_subject_teachers_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `cst_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `cst_s_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `classes` ADD CONSTRAINT `classes_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `classes` ADD CONSTRAINT `c_s_fk` FOREIGN KEY (`school_id`) REFERENCES `schools`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `classes` ADD CONSTRAINT `c_g_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plan_items` ADD CONSTRAINT `course_plan_items_plan_id_course_plans_id_fk` FOREIGN KEY (`plan_id`) REFERENCES `course_plans`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plan_items` ADD CONSTRAINT `cpi_p_fk` FOREIGN KEY (`plan_id`) REFERENCES `course_plans`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `cp_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `cp_s_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `cp_t_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_plans` ADD CONSTRAINT `cp_cb_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_questions` ADD CONSTRAINT `exam_questions_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_questions` ADD CONSTRAINT `exam_questions_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_submissions` ADD CONSTRAINT `exam_submissions_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_submissions` ADD CONSTRAINT `exam_submissions_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD CONSTRAINT `exams_creator_id_users_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD CONSTRAINT `exams_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD CONSTRAINT `exams_grade_id_grades_id_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `file_attachments` ADD CONSTRAINT `file_attachments_uploader_id_users_id_fk` FOREIGN KEY (`uploader_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_recorded_by_users_id_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `gr_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `gr_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `gr_sub_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grade_records` ADD CONSTRAINT `gr_rb_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grades` ADD CONSTRAINT `g_s_fk` FOREIGN KEY (`school_id`) REFERENCES `schools`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grades` ADD CONSTRAINT `g_gh_fk` FOREIGN KEY (`grade_head_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `grades` ADD CONSTRAINT `g_th_fk` FOREIGN KEY (`teaching_head_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_answers` ADD CONSTRAINT `hw_ans_sub_fk` FOREIGN KEY (`submission_id`) REFERENCES `homework_submissions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_answers` ADD CONSTRAINT `hw_ans_q_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignment_questions` ADD CONSTRAINT `hw_aq_a_fk` FOREIGN KEY (`assignment_id`) REFERENCES `homework_assignments`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignment_questions` ADD CONSTRAINT `hw_aq_q_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignment_targets` ADD CONSTRAINT `hw_at_a_fk` FOREIGN KEY (`assignment_id`) REFERENCES `homework_assignments`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignment_targets` ADD CONSTRAINT `hw_at_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignments` ADD CONSTRAINT `hw_asg_exam_fk` FOREIGN KEY (`source_exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignments` ADD CONSTRAINT `hw_asg_creator_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_submissions` ADD CONSTRAINT `hw_sub_a_fk` FOREIGN KEY (`assignment_id`) REFERENCES `homework_assignments`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `homework_submissions` ADD CONSTRAINT `hw_sub_student_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `message_notifications` ADD CONSTRAINT `message_notifications_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `messages` ADD CONSTRAINT `messages_sender_id_users_id_fk` FOREIGN KEY (`sender_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `messages` ADD CONSTRAINT `messages_receiver_id_users_id_fk` FOREIGN KEY (`receiver_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `notification_preferences` ADD CONSTRAINT `notification_preferences_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `notification_preferences` ADD CONSTRAINT `np_u_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `parent_student_relations` ADD CONSTRAINT `parent_student_relations_parent_id_users_id_fk` FOREIGN KEY (`parent_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `parent_student_relations` ADD CONSTRAINT `parent_student_relations_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `parent_student_relations` ADD CONSTRAINT `psr_p_fk` FOREIGN KEY (`parent_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `parent_student_relations` ADD CONSTRAINT `psr_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `password_security` ADD CONSTRAINT `password_security_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `password_security` ADD CONSTRAINT `ps_u_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions` ADD CONSTRAINT `questions_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `q_kp_qid_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `q_kp_kpid_fk` FOREIGN KEY (`knowledge_point_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `role_permissions` ADD CONSTRAINT `role_permissions_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `sessions` ADD CONSTRAINT `sessions_userId_users_id_fk` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `submission_answers` ADD CONSTRAINT `submission_answers_submission_id_exam_submissions_id_fk` FOREIGN KEY (`submission_id`) REFERENCES `exam_submissions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `submission_answers` ADD CONSTRAINT `submission_answers_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `users_to_roles` ADD CONSTRAINT `users_to_roles_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `users_to_roles` ADD CONSTRAINT `users_to_roles_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `academic_years_name_idx` ON `academic_years` (`name`);--> statement-breakpoint
|
||||
CREATE INDEX `academic_years_active_idx` ON `academic_years` (`is_active`);--> statement-breakpoint
|
||||
CREATE INDEX `account_userId_idx` ON `accounts` (`userId`);--> statement-breakpoint
|
||||
CREATE INDEX `ai_provider_idx` ON `ai_providers` (`provider`);--> statement-breakpoint
|
||||
CREATE INDEX `ai_provider_default_idx` ON `ai_providers` (`is_default`);--> statement-breakpoint
|
||||
CREATE INDEX `announcements_author_idx` ON `announcements` (`author_id`);--> statement-breakpoint
|
||||
CREATE INDEX `announcements_status_idx` ON `announcements` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `announcements_type_idx` ON `announcements` (`type`);--> statement-breakpoint
|
||||
CREATE INDEX `announcements_target_grade_idx` ON `announcements` (`target_grade_id`);--> statement-breakpoint
|
||||
CREATE INDEX `announcements_target_class_idx` ON `announcements` (`target_class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_student_idx` ON `attendance_records` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_class_idx` ON `attendance_records` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_date_idx` ON `attendance_records` (`date`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_class_date_idx` ON `attendance_records` (`class_id`,`date`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_student_date_idx` ON `attendance_records` (`student_id`,`date`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_schedule_idx` ON `attendance_records` (`schedule_id`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_records_recorded_by_idx` ON `attendance_records` (`recorded_by`);--> statement-breakpoint
|
||||
CREATE INDEX `attendance_rules_class_idx` ON `attendance_rules` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `audit_logs_user_id_idx` ON `audit_logs` (`user_id`);--> statement-breakpoint
|
||||
CREATE INDEX `audit_logs_module_idx` ON `audit_logs` (`module`);--> statement-breakpoint
|
||||
CREATE INDEX `audit_logs_action_idx` ON `audit_logs` (`action`);--> statement-breakpoint
|
||||
CREATE INDEX `audit_logs_status_idx` ON `audit_logs` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `audit_logs_created_at_idx` ON `audit_logs` (`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `textbook_idx` ON `chapters` (`textbook_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_id_idx` ON `chapters` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_enrollments_class_idx` ON `class_enrollments` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_enrollments_student_idx` ON `class_enrollments` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_schedule_class_idx` ON `class_schedule` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_schedule_class_day_idx` ON `class_schedule` (`class_id`,`weekday`);--> statement-breakpoint
|
||||
CREATE INDEX `class_subject_teachers_class_idx` ON `class_subject_teachers` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_subject_teachers_teacher_idx` ON `class_subject_teachers` (`teacher_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_subject_teachers_subject_id_idx` ON `class_subject_teachers` (`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `classes_teacher_idx` ON `classes` (`teacher_id`);--> statement-breakpoint
|
||||
CREATE INDEX `classes_grade_idx` ON `classes` (`grade`);--> statement-breakpoint
|
||||
CREATE INDEX `classes_school_idx` ON `classes` (`school_id`);--> statement-breakpoint
|
||||
CREATE INDEX `classes_grade_id_idx` ON `classes` (`grade_id`);--> statement-breakpoint
|
||||
CREATE INDEX `classrooms_name_idx` ON `classrooms` (`name`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plan_items_plan_idx` ON `course_plan_items` (`plan_id`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plan_items_plan_week_idx` ON `course_plan_items` (`plan_id`,`week`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plans_class_idx` ON `course_plans` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plans_teacher_idx` ON `course_plans` (`teacher_id`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plans_subject_idx` ON `course_plans` (`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plans_status_idx` ON `course_plans` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `course_plans_class_subject_idx` ON `course_plans` (`class_id`,`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `data_change_logs_table_name_idx` ON `data_change_logs` (`table_name`);--> statement-breakpoint
|
||||
CREATE INDEX `data_change_logs_record_id_idx` ON `data_change_logs` (`record_id`);--> statement-breakpoint
|
||||
CREATE INDEX `data_change_logs_action_idx` ON `data_change_logs` (`action`);--> statement-breakpoint
|
||||
CREATE INDEX `data_change_logs_changed_by_idx` ON `data_change_logs` (`changed_by`);--> statement-breakpoint
|
||||
CREATE INDEX `data_change_logs_created_at_idx` ON `data_change_logs` (`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `departments_name_idx` ON `departments` (`name`);--> statement-breakpoint
|
||||
CREATE INDEX `exam_student_idx` ON `exam_submissions` (`exam_id`,`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `exams_subject_idx` ON `exams` (`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `exams_grade_idx` ON `exams` (`grade_id`);--> statement-breakpoint
|
||||
CREATE INDEX `file_attachments_uploader_idx` ON `file_attachments` (`uploader_id`);--> statement-breakpoint
|
||||
CREATE INDEX `file_attachments_target_idx` ON `file_attachments` (`target_type`,`target_id`);--> statement-breakpoint
|
||||
CREATE INDEX `file_attachments_created_at_idx` ON `file_attachments` (`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `grade_records_student_idx` ON `grade_records` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grade_records_class_idx` ON `grade_records` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grade_records_subject_idx` ON `grade_records` (`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grade_records_exam_idx` ON `grade_records` (`exam_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grade_records_class_subject_idx` ON `grade_records` (`class_id`,`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grade_records_recorded_by_idx` ON `grade_records` (`recorded_by`);--> statement-breakpoint
|
||||
CREATE INDEX `grades_school_idx` ON `grades` (`school_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grades_school_name_uniq` ON `grades` (`school_id`,`name`);--> statement-breakpoint
|
||||
CREATE INDEX `grades_grade_head_idx` ON `grades` (`grade_head_id`);--> statement-breakpoint
|
||||
CREATE INDEX `grades_teaching_head_idx` ON `grades` (`teaching_head_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_answer_submission_idx` ON `homework_answers` (`submission_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_answer_submission_question_idx` ON `homework_answers` (`submission_id`,`question_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_questions_assignment_idx` ON `homework_assignment_questions` (`assignment_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_targets_assignment_idx` ON `homework_assignment_targets` (`assignment_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_targets_student_idx` ON `homework_assignment_targets` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_creator_idx` ON `homework_assignments` (`creator_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_source_exam_idx` ON `homework_assignments` (`source_exam_id`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_status_idx` ON `homework_assignments` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `hw_assignment_student_idx` ON `homework_submissions` (`assignment_id`,`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_id_idx` ON `knowledge_points` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `kp_chapter_id_idx` ON `knowledge_points` (`chapter_id`);--> statement-breakpoint
|
||||
CREATE INDEX `login_logs_user_id_idx` ON `login_logs` (`user_id`);--> statement-breakpoint
|
||||
CREATE INDEX `login_logs_user_email_idx` ON `login_logs` (`user_email`);--> statement-breakpoint
|
||||
CREATE INDEX `login_logs_action_idx` ON `login_logs` (`action`);--> statement-breakpoint
|
||||
CREATE INDEX `login_logs_status_idx` ON `login_logs` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `login_logs_created_at_idx` ON `login_logs` (`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `message_notifications_user_idx` ON `message_notifications` (`user_id`);--> statement-breakpoint
|
||||
CREATE INDEX `message_notifications_is_read_idx` ON `message_notifications` (`is_read`);--> statement-breakpoint
|
||||
CREATE INDEX `message_notifications_user_read_idx` ON `message_notifications` (`user_id`,`is_read`);--> statement-breakpoint
|
||||
CREATE INDEX `message_notifications_created_at_idx` ON `message_notifications` (`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `messages_sender_idx` ON `messages` (`sender_id`);--> statement-breakpoint
|
||||
CREATE INDEX `messages_receiver_idx` ON `messages` (`receiver_id`);--> statement-breakpoint
|
||||
CREATE INDEX `messages_is_read_idx` ON `messages` (`is_read`);--> statement-breakpoint
|
||||
CREATE INDEX `messages_parent_idx` ON `messages` (`parent_message_id`);--> statement-breakpoint
|
||||
CREATE INDEX `messages_receiver_read_idx` ON `messages` (`receiver_id`,`is_read`);--> statement-breakpoint
|
||||
CREATE INDEX `notification_preferences_user_idx` ON `notification_preferences` (`user_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_student_relations_parent_idx` ON `parent_student_relations` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_student_relations_student_idx` ON `parent_student_relations` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `password_security_user_idx` ON `password_security` (`user_id`);--> statement-breakpoint
|
||||
CREATE INDEX `parent_id_idx` ON `questions` (`parent_id`);--> statement-breakpoint
|
||||
CREATE INDEX `author_id_idx` ON `questions` (`author_id`);--> statement-breakpoint
|
||||
CREATE INDEX `kp_idx` ON `questions_to_knowledge_points` (`knowledge_point_id`);--> statement-breakpoint
|
||||
CREATE INDEX `role_permissions_role_idx` ON `role_permissions` (`role_id`);--> statement-breakpoint
|
||||
CREATE INDEX `schedule_changes_class_idx` ON `schedule_changes` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `schedule_changes_status_idx` ON `schedule_changes` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `schedule_changes_requested_by_idx` ON `schedule_changes` (`requested_by`);--> statement-breakpoint
|
||||
CREATE INDEX `schedule_changes_original_schedule_idx` ON `schedule_changes` (`original_schedule_id`);--> statement-breakpoint
|
||||
CREATE INDEX `scheduling_rules_class_idx` ON `scheduling_rules` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `schools_name_idx` ON `schools` (`name`);--> statement-breakpoint
|
||||
CREATE INDEX `schools_code_idx` ON `schools` (`code`);--> statement-breakpoint
|
||||
CREATE INDEX `session_userId_idx` ON `sessions` (`userId`);--> statement-breakpoint
|
||||
CREATE INDEX `subjects_name_idx` ON `subjects` (`name`);--> statement-breakpoint
|
||||
CREATE INDEX `submission_idx` ON `submission_answers` (`submission_id`);--> statement-breakpoint
|
||||
CREATE INDEX `email_idx` ON `users` (`email`);--> statement-breakpoint
|
||||
CREATE INDEX `users_grade_id_idx` ON `users` (`grade_id`);--> statement-breakpoint
|
||||
CREATE INDEX `users_department_id_idx` ON `users` (`department_id`);--> statement-breakpoint
|
||||
CREATE INDEX `user_id_idx` ON `users_to_roles` (`user_id`);
|
||||
@@ -1,115 +0,0 @@
|
||||
CREATE TABLE `course_selections` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`course_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`selection_status` enum('selected','enrolled','waitlist','dropped','rejected') NOT NULL DEFAULT 'selected',
|
||||
`priority` int DEFAULT 1,
|
||||
`selected_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`enrolled_at` timestamp,
|
||||
`dropped_at` timestamp,
|
||||
`lottery_rank` int,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `course_selections_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `elective_courses` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`subject_id` varchar(128),
|
||||
`teacher_id` varchar(128) NOT NULL,
|
||||
`grade_id` varchar(128),
|
||||
`description` text,
|
||||
`capacity` int NOT NULL DEFAULT 30,
|
||||
`enrolled_count` int NOT NULL DEFAULT 0,
|
||||
`classroom` varchar(100),
|
||||
`schedule` varchar(255),
|
||||
`start_date` date,
|
||||
`end_date` date,
|
||||
`selection_start_at` datetime,
|
||||
`selection_end_at` datetime,
|
||||
`status` enum('draft','open','closed','cancelled') NOT NULL DEFAULT 'draft',
|
||||
`selection_mode` enum('fcfs','lottery') NOT NULL DEFAULT 'fcfs',
|
||||
`credit` decimal(3,1) DEFAULT '1.0',
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `elective_courses_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `exam_proctoring_events` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`submission_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`exam_id` varchar(128) NOT NULL,
|
||||
`event_type` enum('tab_switch','window_blur','copy_attempt','paste_attempt','right_click','devtools_open','fullscreen_exit','idle_timeout') NOT NULL,
|
||||
`event_detail` text,
|
||||
`occurred_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `exam_proctoring_events_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `knowledge_point_mastery` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`knowledge_point_id` varchar(128) NOT NULL,
|
||||
`mastery_level` decimal(5,2) NOT NULL DEFAULT '0',
|
||||
`total_questions` int NOT NULL DEFAULT 0,
|
||||
`correct_questions` int NOT NULL DEFAULT 0,
|
||||
`last_assessed_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `knowledge_point_mastery_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `learning_diagnostic_reports` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`generated_by` varchar(128),
|
||||
`report_type` enum('individual','class','grade') NOT NULL DEFAULT 'individual',
|
||||
`period` varchar(50),
|
||||
`summary` text,
|
||||
`strengths` json,
|
||||
`weaknesses` json,
|
||||
`recommendations` json,
|
||||
`overall_score` decimal(5,2),
|
||||
`report_status` enum('draft','published','archived') NOT NULL DEFAULT 'draft',
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `learning_diagnostic_reports_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD `exam_mode` enum('homework','timed','proctored') DEFAULT 'homework';--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD `duration_minutes` int;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD `shuffle_questions` boolean DEFAULT false;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD `allow_late_start` boolean DEFAULT false;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD `late_start_grace_minutes` int DEFAULT 0;--> statement-breakpoint
|
||||
ALTER TABLE `exams` ADD `anti_cheat_enabled` boolean DEFAULT false;--> statement-breakpoint
|
||||
ALTER TABLE `course_selections` ADD CONSTRAINT `course_selections_course_id_elective_courses_id_fk` FOREIGN KEY (`course_id`) REFERENCES `elective_courses`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `course_selections` ADD CONSTRAINT `course_selections_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `elective_courses` ADD CONSTRAINT `elective_courses_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `elective_courses` ADD CONSTRAINT `elective_courses_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `elective_courses` ADD CONSTRAINT `elective_courses_grade_id_grades_id_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_proctoring_events` ADD CONSTRAINT `exam_proctoring_events_submission_id_exam_submissions_id_fk` FOREIGN KEY (`submission_id`) REFERENCES `exam_submissions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_proctoring_events` ADD CONSTRAINT `exam_proctoring_events_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `exam_proctoring_events` ADD CONSTRAINT `exam_proctoring_events_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `knowledge_point_mastery` ADD CONSTRAINT `knowledge_point_mastery_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `knowledge_point_mastery` ADD CONSTRAINT `knowledge_point_mastery_knowledge_point_id_knowledge_points_id_fk` FOREIGN KEY (`knowledge_point_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `learning_diagnostic_reports` ADD CONSTRAINT `learning_diagnostic_reports_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `learning_diagnostic_reports` ADD CONSTRAINT `learning_diagnostic_reports_generated_by_users_id_fk` FOREIGN KEY (`generated_by`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `course_selections_course_idx` ON `course_selections` (`course_id`);--> statement-breakpoint
|
||||
CREATE INDEX `course_selections_student_idx` ON `course_selections` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `course_selections_status_idx` ON `course_selections` (`selection_status`);--> statement-breakpoint
|
||||
CREATE INDEX `elective_courses_teacher_idx` ON `elective_courses` (`teacher_id`);--> statement-breakpoint
|
||||
CREATE INDEX `elective_courses_subject_idx` ON `elective_courses` (`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `elective_courses_grade_idx` ON `elective_courses` (`grade_id`);--> statement-breakpoint
|
||||
CREATE INDEX `elective_courses_status_idx` ON `elective_courses` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `proctoring_submission_idx` ON `exam_proctoring_events` (`submission_id`);--> statement-breakpoint
|
||||
CREATE INDEX `proctoring_student_idx` ON `exam_proctoring_events` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `proctoring_exam_idx` ON `exam_proctoring_events` (`exam_id`);--> statement-breakpoint
|
||||
CREATE INDEX `proctoring_event_type_idx` ON `exam_proctoring_events` (`event_type`);--> statement-breakpoint
|
||||
CREATE INDEX `mastery_student_idx` ON `knowledge_point_mastery` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `mastery_kp_idx` ON `knowledge_point_mastery` (`knowledge_point_id`);--> statement-breakpoint
|
||||
CREATE INDEX `diagnostic_student_idx` ON `learning_diagnostic_reports` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `diagnostic_generated_by_idx` ON `learning_diagnostic_reports` (`generated_by`);--> statement-breakpoint
|
||||
CREATE INDEX `diagnostic_status_idx` ON `learning_diagnostic_reports` (`report_status`);--> statement-breakpoint
|
||||
CREATE INDEX `diagnostic_report_type_idx` ON `learning_diagnostic_reports` (`report_type`);
|
||||
@@ -1,58 +0,0 @@
|
||||
CREATE TABLE `lesson_plan_templates` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`type` varchar(50) NOT NULL,
|
||||
`scope` varchar(50) NOT NULL,
|
||||
`blocks` json NOT NULL,
|
||||
`creator_id` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `lesson_plan_templates_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `lesson_plan_versions` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`plan_id` varchar(128) NOT NULL,
|
||||
`version_no` int NOT NULL,
|
||||
`label` varchar(100),
|
||||
`content` json NOT NULL,
|
||||
`is_auto` boolean NOT NULL DEFAULT false,
|
||||
`creator_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `lesson_plan_versions_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `lesson_plans` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`textbook_id` varchar(128),
|
||||
`chapter_id` varchar(128),
|
||||
`course_plan_item_id` varchar(128),
|
||||
`subject_id` varchar(128),
|
||||
`grade_id` varchar(128),
|
||||
`template_id` varchar(128),
|
||||
`template_name` varchar(100),
|
||||
`content` json NOT NULL,
|
||||
`status` varchar(50) NOT NULL DEFAULT 'draft',
|
||||
`creator_id` varchar(128) NOT NULL,
|
||||
`last_saved_at` timestamp,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `lesson_plans_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plan_templates` ADD CONSTRAINT `lesson_plan_templates_creator_id_users_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plan_versions` ADD CONSTRAINT `lesson_plan_versions_plan_id_lesson_plans_id_fk` FOREIGN KEY (`plan_id`) REFERENCES `lesson_plans`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plan_versions` ADD CONSTRAINT `lesson_plan_versions_creator_id_users_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plans` ADD CONSTRAINT `lesson_plans_textbook_id_textbooks_id_fk` FOREIGN KEY (`textbook_id`) REFERENCES `textbooks`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plans` ADD CONSTRAINT `lesson_plans_chapter_id_chapters_id_fk` FOREIGN KEY (`chapter_id`) REFERENCES `chapters`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plans` ADD CONSTRAINT `lesson_plans_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plans` ADD CONSTRAINT `lesson_plans_grade_id_grades_id_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `lesson_plans` ADD CONSTRAINT `lesson_plans_creator_id_users_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `lpt_type_creator_idx` ON `lesson_plan_templates` (`type`,`creator_id`);--> statement-breakpoint
|
||||
CREATE INDEX `lpv_plan_version_idx` ON `lesson_plan_versions` (`plan_id`,`version_no`);--> statement-breakpoint
|
||||
CREATE INDEX `lpv_plan_created_idx` ON `lesson_plan_versions` (`plan_id`,`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `lp_creator_idx` ON `lesson_plans` (`creator_id`);--> statement-breakpoint
|
||||
CREATE INDEX `lp_status_idx` ON `lesson_plans` (`status`);--> statement-breakpoint
|
||||
CREATE INDEX `lp_textbook_chapter_idx` ON `lesson_plans` (`textbook_id`,`chapter_id`);--> statement-breakpoint
|
||||
CREATE INDEX `lp_subject_grade_idx` ON `lesson_plans` (`subject_id`,`grade_id`);
|
||||
@@ -1,45 +0,0 @@
|
||||
CREATE TABLE `class_invitation_codes` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`code` varchar(8) NOT NULL,
|
||||
`class_invitation_code_status` enum('active','disabled','expired','exhausted') NOT NULL DEFAULT 'active',
|
||||
`max_uses` int,
|
||||
`used_count` int NOT NULL DEFAULT 0,
|
||||
`expires_at` timestamp,
|
||||
`created_by` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
`revoked_at` timestamp,
|
||||
`revoked_by` varchar(128),
|
||||
`note` varchar(255),
|
||||
CONSTRAINT `class_invitation_codes_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `class_invitation_codes_code_unique` UNIQUE(`code`),
|
||||
CONSTRAINT `class_invitation_codes_code_idx` UNIQUE(`code`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `system_settings` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`category` varchar(50) NOT NULL,
|
||||
`key` varchar(100) NOT NULL,
|
||||
`value` text NOT NULL,
|
||||
`value_type` varchar(20) NOT NULL DEFAULT 'string',
|
||||
`updated_by` varchar(128),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `system_settings_id` PRIMARY KEY(`id`),
|
||||
CONSTRAINT `ss_category_key_idx` UNIQUE(`category`,`key`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `homework_assignments` MODIFY COLUMN `source_exam_id` varchar(128);--> statement-breakpoint
|
||||
ALTER TABLE `learning_diagnostic_reports` MODIFY COLUMN `student_id` varchar(128);--> statement-breakpoint
|
||||
ALTER TABLE `messages` ADD `sender_deleted_at` timestamp;--> statement-breakpoint
|
||||
ALTER TABLE `messages` ADD `receiver_deleted_at` timestamp;--> statement-breakpoint
|
||||
ALTER TABLE `notification_preferences` ADD `quiet_hours_enabled` boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE `notification_preferences` ADD `quiet_hours_start` varchar(5);--> statement-breakpoint
|
||||
ALTER TABLE `notification_preferences` ADD `quiet_hours_end` varchar(5);--> statement-breakpoint
|
||||
ALTER TABLE `class_invitation_codes` ADD CONSTRAINT `class_invitation_codes_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_invitation_codes` ADD CONSTRAINT `class_invitation_codes_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `class_invitation_codes` ADD CONSTRAINT `cic_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `class_invitation_codes_class_idx` ON `class_invitation_codes` (`class_id`);--> statement-breakpoint
|
||||
CREATE INDEX `class_invitation_codes_status_expires_idx` ON `class_invitation_codes` (`class_invitation_code_status`,`expires_at`);--> statement-breakpoint
|
||||
CREATE INDEX `ss_category_idx` ON `system_settings` (`category`);
|
||||
@@ -1,11 +0,0 @@
|
||||
CREATE TABLE `knowledge_point_prerequisites` (
|
||||
`knowledge_point_id` varchar(128) NOT NULL,
|
||||
`prerequisite_kp_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `knowledge_point_prerequisites_knowledge_point_id_prerequisite_kp_id_pk` PRIMARY KEY(`knowledge_point_id`,`prerequisite_kp_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `knowledge_point_prerequisites` ADD CONSTRAINT `kp_prereq_kp_fk` FOREIGN KEY (`knowledge_point_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `knowledge_point_prerequisites` ADD CONSTRAINT `kp_prereq_prereq_fk` FOREIGN KEY (`prerequisite_kp_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `kp_prereq_kp_idx` ON `knowledge_point_prerequisites` (`knowledge_point_id`);--> statement-breakpoint
|
||||
CREATE INDEX `kp_prereq_prereq_idx` ON `knowledge_point_prerequisites` (`prerequisite_kp_id`);
|
||||
@@ -1,48 +0,0 @@
|
||||
CREATE TABLE `error_book_items` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`source_type` enum('exam','homework','manual') NOT NULL DEFAULT 'manual',
|
||||
`source_id` varchar(128),
|
||||
`student_answer` json,
|
||||
`correct_answer` json,
|
||||
`subject_id` varchar(128),
|
||||
`knowledge_point_ids` json,
|
||||
`error_status` enum('new','learning','mastered','archived') NOT NULL DEFAULT 'new',
|
||||
`mastery_level` int NOT NULL DEFAULT 0,
|
||||
`next_review_at` timestamp,
|
||||
`review_interval` int NOT NULL DEFAULT 1,
|
||||
`review_count` int NOT NULL DEFAULT 0,
|
||||
`correct_streak` int NOT NULL DEFAULT 0,
|
||||
`note` text,
|
||||
`error_tags` json,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `error_book_items_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `error_book_reviews` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`item_id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`review_result` enum('again','hard','good','easy') NOT NULL,
|
||||
`reviewed_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`new_interval` int,
|
||||
`new_mastery_level` int,
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
CONSTRAINT `error_book_reviews_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `error_book_items` ADD CONSTRAINT `error_book_items_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `error_book_items` ADD CONSTRAINT `error_book_items_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `error_book_reviews` ADD CONSTRAINT `error_book_reviews_item_id_error_book_items_id_fk` FOREIGN KEY (`item_id`) REFERENCES `error_book_items`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `error_book_reviews` ADD CONSTRAINT `error_book_reviews_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `eb_item_student_idx` ON `error_book_items` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_item_student_status_idx` ON `error_book_items` (`student_id`,`error_status`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_item_student_review_idx` ON `error_book_items` (`student_id`,`next_review_at`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_item_question_idx` ON `error_book_items` (`question_id`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_item_subject_idx` ON `error_book_items` (`subject_id`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_item_source_idx` ON `error_book_items` (`source_type`,`source_id`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_review_item_idx` ON `error_book_reviews` (`item_id`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_review_student_idx` ON `error_book_reviews` (`student_id`);--> statement-breakpoint
|
||||
CREATE INDEX `eb_review_student_reviewed_idx` ON `error_book_reviews` (`student_id`,`reviewed_at`);
|
||||
@@ -1,15 +0,0 @@
|
||||
CREATE TABLE `notification_logs` (
|
||||
`id` varchar(128) PRIMARY KEY NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`channel` varchar(32) NOT NULL,
|
||||
`status` varchar(16) NOT NULL,
|
||||
`message_id` varchar(255),
|
||||
`error` text,
|
||||
`sent_at` timestamp DEFAULT (now()) NOT NULL,
|
||||
CONSTRAINT `notification_logs_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action
|
||||
);
|
||||
CREATE INDEX `notification_logs_user_idx` ON `notification_logs`(`user_id`);
|
||||
CREATE INDEX `notification_logs_channel_idx` ON `notification_logs`(`channel`);
|
||||
CREATE INDEX `notification_logs_status_idx` ON `notification_logs`(`status`);
|
||||
CREATE INDEX `notification_logs_sent_at_idx` ON `notification_logs`(`sent_at`);
|
||||
@@ -1,4 +0,0 @@
|
||||
ALTER TABLE `message_notifications` ADD COLUMN `priority` varchar(16) DEFAULT 'normal' NOT NULL;
|
||||
ALTER TABLE `message_notifications` ADD COLUMN `is_archived` boolean DEFAULT false NOT NULL;
|
||||
CREATE INDEX `message_notifications_priority_idx` ON `message_notifications`(`priority`);
|
||||
CREATE INDEX `message_notifications_user_archived_idx` ON `message_notifications`(`user_id`, `is_archived`);
|
||||
@@ -1,17 +0,0 @@
|
||||
ALTER TABLE `messages` ADD COLUMN `is_starred` boolean DEFAULT false NOT NULL;
|
||||
CREATE INDEX `messages_receiver_starred_idx` ON `messages`(`receiver_id`, `is_starred`);
|
||||
|
||||
CREATE TABLE `message_drafts` (
|
||||
`id` varchar(128) PRIMARY KEY NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`receiver_id` varchar(128),
|
||||
`subject` varchar(255),
|
||||
`content` text,
|
||||
`parent_message_id` varchar(128),
|
||||
`updated_at` timestamp DEFAULT (now()) ON UPDATE now() NOT NULL,
|
||||
`created_at` timestamp DEFAULT (now()) NOT NULL,
|
||||
CONSTRAINT `message_drafts_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action,
|
||||
CONSTRAINT `message_drafts_receiver_id_users_id_fk` FOREIGN KEY (`receiver_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action
|
||||
);
|
||||
CREATE INDEX `message_drafts_user_idx` ON `message_drafts`(`user_id`);
|
||||
CREATE INDEX `message_drafts_user_updated_idx` ON `message_drafts`(`user_id`, `updated_at`);
|
||||
@@ -1,14 +0,0 @@
|
||||
ALTER TABLE `announcements` ADD COLUMN `is_pinned` boolean DEFAULT false NOT NULL;
|
||||
CREATE INDEX `announcements_status_pinned_idx` ON `announcements`(`status`, `is_pinned`);
|
||||
|
||||
CREATE TABLE `announcement_reads` (
|
||||
`id` varchar(128) PRIMARY KEY NOT NULL,
|
||||
`announcement_id` varchar(128) NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`read_at` timestamp DEFAULT (now()) NOT NULL,
|
||||
CONSTRAINT `announcement_reads_announcement_id_announcements_id_fk` FOREIGN KEY (`announcement_id`) REFERENCES `announcements`(`id`) ON DELETE cascade ON UPDATE no action,
|
||||
CONSTRAINT `announcement_reads_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action
|
||||
);
|
||||
CREATE INDEX `announcement_reads_announcement_idx` ON `announcement_reads`(`announcement_id`);
|
||||
CREATE INDEX `announcement_reads_user_idx` ON `announcement_reads`(`user_id`);
|
||||
CREATE UNIQUE INDEX `announcement_reads_unique_idx` ON `announcement_reads`(`announcement_id`, `user_id`);
|
||||
@@ -1,14 +0,0 @@
|
||||
CREATE TABLE `grade_record_answers` (
|
||||
`id` varchar(128) PRIMARY KEY NOT NULL,
|
||||
`grade_record_id` varchar(128) NOT NULL,
|
||||
`question_id` varchar(128) NOT NULL,
|
||||
`score` decimal(6, 2) NOT NULL,
|
||||
`full_score` decimal(6, 2) NOT NULL,
|
||||
`feedback` text,
|
||||
`created_at` timestamp DEFAULT (now()) NOT NULL,
|
||||
`updated_at` timestamp DEFAULT (now()) NOT NULL,
|
||||
CONSTRAINT `gra_gr_fk` FOREIGN KEY (`grade_record_id`) REFERENCES `grade_records`(`id`) ON DELETE cascade ON UPDATE no action,
|
||||
CONSTRAINT `gra_q_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action
|
||||
);
|
||||
CREATE INDEX `grade_record_answers_record_idx` ON `grade_record_answers`(`grade_record_id`);
|
||||
CREATE INDEX `grade_record_answers_question_idx` ON `grade_record_answers`(`question_id`);
|
||||
@@ -1,85 +0,0 @@
|
||||
-- 0011_rbac_role_flags_and_seed.sql
|
||||
-- RBAC: add is_system/is_enabled columns to roles table and seed role_permissions.
|
||||
|
||||
-- 1. Add is_system and is_enabled columns to roles table.
|
||||
ALTER TABLE `roles`
|
||||
ADD COLUMN `is_system` boolean DEFAULT false NOT NULL,
|
||||
ADD COLUMN `is_enabled` boolean DEFAULT true NOT NULL;
|
||||
|
||||
-- 2. Mark the 6 builtin roles as system roles.
|
||||
UPDATE `roles` SET `is_system` = true
|
||||
WHERE `name` IN ('admin', 'teacher', 'student', 'parent', 'grade_head', 'teaching_head');
|
||||
|
||||
-- 3. Seed role_permissions for builtin roles.
|
||||
-- Uses INSERT IGNORE so re-running is safe (role_permissions has a composite PK).
|
||||
-- Permissions are resolved from ROLE_PERMISSIONS_SEED in src/shared/lib/permissions.ts.
|
||||
|
||||
-- admin
|
||||
INSERT IGNORE INTO `role_permissions` (`role_id`, `permission`)
|
||||
SELECT id, 'exam:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:duplicate' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:publish' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:ai_generate' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'homework:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'homework:grade' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'question:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'question:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'question:update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'question:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'textbook:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'textbook:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'textbook:update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'textbook:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'class:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'class:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'class:update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'class:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'class:enroll' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'class:schedule' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'school:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'grade:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'user:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'user:profile_update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'ai:chat' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'ai:configure' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'settings:admin' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'audit_log:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'announcement:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'announcement:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'grade_record:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'grade_record:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'course_plan:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'course_plan:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'attendance:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'attendance:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'message:send' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'message:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'message:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'schedule:auto' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'schedule:adjust' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'elective:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'elective:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:proctor' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'exam:proctor:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'diagnostic:manage' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'diagnostic:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'lesson_plan:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'lesson_plan:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'lesson_plan:update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'lesson_plan:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'lesson_plan:publish' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'file:upload' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'file:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'file:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'dashboard:admin_read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'error_book:analytics_read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'adaptive_practice:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'role:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'role:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'role:update' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'role:delete' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'role:assign' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'permission:read' FROM `roles` WHERE `name` = 'admin';
|
||||
@@ -1,4 +0,0 @@
|
||||
-- v4-P2-3: Add gradeId column to learning_diagnostic_reports for grade-level diagnostic reports
|
||||
ALTER TABLE `learning_diagnostic_reports` ADD COLUMN `grade_id` varchar(128);--> statement-breakpoint
|
||||
ALTER TABLE `learning_diagnostic_reports` ADD CONSTRAINT `learning_diagnostic_reports_grade_id_grades_id_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `diagnostic_grade_idx` ON `learning_diagnostic_reports` (`grade_id`);
|
||||
@@ -1,2 +0,0 @@
|
||||
-- P2-4: 消息撤回功能(2 分钟窗口)
|
||||
ALTER TABLE `messages` ADD COLUMN `recalled_at` timestamp;
|
||||
@@ -1,13 +0,0 @@
|
||||
-- P2-6: 快捷回复模板
|
||||
CREATE TABLE `message_templates` (
|
||||
`id` varchar(128) PRIMARY KEY NOT NULL,
|
||||
`user_id` varchar(128) NOT NULL,
|
||||
`title` varchar(100) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`sort_order` integer DEFAULT 0 NOT NULL,
|
||||
`updated_at` timestamp DEFAULT (now()) ON UPDATE now() NOT NULL,
|
||||
`created_at` timestamp DEFAULT (now()) NOT NULL,
|
||||
CONSTRAINT `message_templates_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action
|
||||
);
|
||||
CREATE INDEX `message_templates_user_idx` ON `message_templates`(`user_id`);
|
||||
CREATE INDEX `message_templates_user_sort_idx` ON `message_templates`(`user_id`, `sort_order`);
|
||||
@@ -1,3 +0,0 @@
|
||||
-- P2-2: 群组消息(教师→全班家长,fan-out on write)
|
||||
ALTER TABLE `messages` ADD COLUMN `group_message_id` varchar(128);
|
||||
CREATE INDEX `messages_group_message_idx` ON `messages`(`group_message_id`);
|
||||
@@ -1,19 +0,0 @@
|
||||
-- audit-P2-3: 注册邀请码表(admin 批量生成,注册时校验 + 自动分配角色/班级)
|
||||
CREATE TABLE IF NOT EXISTS `invitation_codes` (
|
||||
`id` serial PRIMARY KEY,
|
||||
`code` varchar(64) NOT NULL,
|
||||
`email` varchar(255),
|
||||
`role` varchar(50) NOT NULL,
|
||||
`class_id` varchar(128),
|
||||
`notes` varchar(500),
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`created_by` varchar(128),
|
||||
`expires_at` timestamp NULL,
|
||||
`used_by` varchar(128),
|
||||
`used_at` timestamp NULL,
|
||||
UNIQUE KEY `invitation_codes_code_unique` (`code`)
|
||||
);
|
||||
|
||||
CREATE INDEX `invitation_codes_code_idx` ON `invitation_codes`(`code`);
|
||||
CREATE INDEX `invitation_codes_email_idx` ON `invitation_codes`(`email`);
|
||||
CREATE INDEX `invitation_codes_used_by_idx` ON `invitation_codes`(`used_by`);
|
||||
@@ -1,35 +0,0 @@
|
||||
-- P2-5: 消息举报 + 用户屏蔽
|
||||
-- 1. message_reports: 举报记录(reporterId → messageId / reportedUserId)
|
||||
-- 2. user_blocks: 用户屏蔽关系(blockerId → blockedId,唯一约束防重复)
|
||||
|
||||
CREATE TABLE `message_reports` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`reporter_id` varchar(128) NOT NULL,
|
||||
`message_id` varchar(128) NOT NULL,
|
||||
`reported_user_id` varchar(128) NOT NULL,
|
||||
`reason` varchar(50) NOT NULL,
|
||||
`description` text,
|
||||
`status` varchar(20) NOT NULL DEFAULT 'pending',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `message_reports_reporter_idx` (`reporter_id`),
|
||||
INDEX `message_reports_message_idx` (`message_id`),
|
||||
INDEX `message_reports_reported_user_idx` (`reported_user_id`),
|
||||
INDEX `message_reports_status_idx` (`status`),
|
||||
CONSTRAINT `message_reports_reporter_id_users_id_fk` FOREIGN KEY (`reporter_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `message_reports_message_id_messages_id_fk` FOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `message_reports_reported_user_id_users_id_fk` FOREIGN KEY (`reported_user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE `user_blocks` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`blocker_id` varchar(128) NOT NULL,
|
||||
`blocked_id` varchar(128) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `user_blocks_blocker_blocked_uniq` (`blocker_id`, `blocked_id`),
|
||||
INDEX `user_blocks_blocker_idx` (`blocker_id`),
|
||||
CONSTRAINT `user_blocks_blocker_id_users_id_fk` FOREIGN KEY (`blocker_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `user_blocks_blocked_id_users_id_fk` FOREIGN KEY (`blocked_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
@@ -1,8 +0,0 @@
|
||||
-- P2-10: 跨设备草稿同步
|
||||
-- 1. 新增 device_id 列(标识来源设备)
|
||||
-- 2. 新增 version 列(乐观锁,冲突检测)
|
||||
-- 3. 新增 (user_id, parent_message_id) 索引(按会话查询最新版本草稿)
|
||||
|
||||
ALTER TABLE `message_drafts` ADD COLUMN `device_id` varchar(128);
|
||||
ALTER TABLE `message_drafts` ADD COLUMN `version` int NOT NULL DEFAULT 1;
|
||||
CREATE INDEX `message_drafts_user_parent_idx` ON `message_drafts`(`user_id`, `parent_message_id`);
|
||||
@@ -1,11 +0,0 @@
|
||||
-- L-1: 考勤状态细分 + 原因字段
|
||||
-- 1. 扩展 attendance_records.status 枚举:新增 'school_activity'(校内活动请假,如运动会、研学、社团活动)
|
||||
-- 2. 新增 reason 字段:记录缺勤/迟到/早退/请假的具体原因(最多 255 字符),与 remark 区分
|
||||
-- - remark:教师备注(自由文本,可记录点名时观察到的情况)
|
||||
-- - reason:标准化原因(用于统计与家长通知,如"病假-感冒"、"家中有事"等)
|
||||
|
||||
ALTER TABLE `attendance_records`
|
||||
MODIFY COLUMN `status`
|
||||
ENUM('present','absent','late','early_leave','excused','school_activity') NOT NULL;
|
||||
|
||||
ALTER TABLE `attendance_records` ADD COLUMN `reason` varchar(255);
|
||||
@@ -1,6 +0,0 @@
|
||||
-- L-3:出勤率阈值预警
|
||||
-- 新增 attendance_rate_threshold(出勤率阈值,默认 90%)
|
||||
-- 新增 consecutive_absence_threshold(连续缺勤阈值,默认 3 次)
|
||||
ALTER TABLE `attendance_rules`
|
||||
ADD COLUMN `attendance_rate_threshold` int DEFAULT 90,
|
||||
ADD COLUMN `consecutive_absence_threshold` int DEFAULT 3;
|
||||
@@ -1,53 +0,0 @@
|
||||
-- 0020_leave_requests.sql
|
||||
-- L-5 在线请假流程:创建 leave_requests 表。
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `leave_requests` (
|
||||
`id` varchar(128) NOT NULL,
|
||||
`student_id` varchar(128) NOT NULL,
|
||||
`requester_id` varchar(128) NOT NULL,
|
||||
`class_id` varchar(128) NOT NULL,
|
||||
`leave_type` enum('sick','personal','family','other') NOT NULL,
|
||||
`start_date` date NOT NULL,
|
||||
`end_date` date NOT NULL,
|
||||
`reason` text NOT NULL,
|
||||
`status` enum('pending','approved','rejected','cancelled') NOT NULL DEFAULT 'pending',
|
||||
`reviewer_id` varchar(128) DEFAULT NULL,
|
||||
`review_comment` text,
|
||||
`reviewed_at` timestamp NULL DEFAULT NULL,
|
||||
`attendance_synced` boolean NOT NULL DEFAULT false,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `leave_requests_student_idx` (`student_id`),
|
||||
KEY `leave_requests_requester_idx` (`requester_id`),
|
||||
KEY `leave_requests_class_idx` (`class_id`),
|
||||
KEY `leave_requests_status_idx` (`status`),
|
||||
KEY `leave_requests_reviewer_idx` (`reviewer_id`),
|
||||
KEY `leave_requests_class_status_idx` (`class_id`, `status`),
|
||||
KEY `leave_requests_student_status_idx` (`student_id`, `status`),
|
||||
CONSTRAINT `lr_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `lr_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `lr_rq_fk` FOREIGN KEY (`requester_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `lr_rv_fk` FOREIGN KEY (`reviewer_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- 为 builtin 角色注入新权限(INSERT IGNORE 幂等)
|
||||
-- admin:三个权限全有
|
||||
INSERT IGNORE INTO `role_permissions` (`role_id`, `permission`)
|
||||
SELECT id, 'leave_request:create' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'leave_request:read' FROM `roles` WHERE `name` = 'admin'
|
||||
UNION ALL SELECT id, 'leave_request:review' FROM `roles` WHERE `name` = 'admin'
|
||||
-- teacher:read + review(班主任审批本班请假)
|
||||
UNION ALL SELECT id, 'leave_request:read' FROM `roles` WHERE `name` = 'teacher'
|
||||
UNION ALL SELECT id, 'leave_request:review' FROM `roles` WHERE `name` = 'teacher'
|
||||
-- parent:create + read(代子女提交、查看子女请假记录)
|
||||
UNION ALL SELECT id, 'leave_request:create' FROM `roles` WHERE `name` = 'parent'
|
||||
UNION ALL SELECT id, 'leave_request:read' FROM `roles` WHERE `name` = 'parent'
|
||||
-- student:create + read(本人提交、查看本人请假记录)
|
||||
UNION ALL SELECT id, 'leave_request:create' FROM `roles` WHERE `name` = 'student'
|
||||
UNION ALL SELECT id, 'leave_request:read' FROM `roles` WHERE `name` = 'student'
|
||||
-- grade_head / teaching_head:read + review(年级主任/教务主任可审批)
|
||||
UNION ALL SELECT id, 'leave_request:read' FROM `roles` WHERE `name` = 'grade_head'
|
||||
UNION ALL SELECT id, 'leave_request:review' FROM `roles` WHERE `name` = 'grade_head'
|
||||
UNION ALL SELECT id, 'leave_request:read' FROM `roles` WHERE `name` = 'teaching_head'
|
||||
UNION ALL SELECT id, 'leave_request:review' FROM `roles` WHERE `name` = 'teaching_head';
|
||||
@@ -1,20 +0,0 @@
|
||||
-- 0021_attendance_period.sql
|
||||
-- L-6 节次考勤:为 attendance_records 表添加 period 字段。
|
||||
--
|
||||
-- 节次枚举:
|
||||
-- morning_reading 早读
|
||||
-- morning 上午
|
||||
-- afternoon 下午
|
||||
-- evening 晚自习
|
||||
-- full_day 全日(默认值,向后兼容:null 也表示全日)
|
||||
--
|
||||
-- 向后兼容策略:
|
||||
-- - 新增 period 列为 NULLABLE,已有数据保持 NULL(视为 full_day)
|
||||
-- - 新记录由应用层显式写入 period;未指定时写入 'full_day'
|
||||
-- - 查询层 period IS NULL OR period = 'full_day' 均视为全日记录
|
||||
|
||||
ALTER TABLE `attendance_records`
|
||||
ADD COLUMN `period` ENUM('morning_reading','morning','afternoon','evening','full_day') NULL DEFAULT NULL AFTER `date`;
|
||||
|
||||
-- 复合索引:班级 + 日期 + 节次,支持按节次查询班级当日点名
|
||||
CREATE INDEX `attendance_records_class_date_period_idx` ON `attendance_records` (`class_id`, `date`, `period`);
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -5,92 +5,8 @@
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1781676504560,
|
||||
"tag": "0000_perfect_pestilence",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1781679978738,
|
||||
"tag": "0001_heavy_sage",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "5",
|
||||
"when": 1781789296745,
|
||||
"tag": "0002_tiny_lionheart",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "5",
|
||||
"when": 1782118370256,
|
||||
"tag": "0003_diagnostic_student_nullable",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "5",
|
||||
"when": 1782136411839,
|
||||
"tag": "0004_calm_sandman",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "5",
|
||||
"when": 1782141546400,
|
||||
"tag": "0005_messy_pride",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "5",
|
||||
"when": 1782374400000,
|
||||
"tag": "0013_message_recall",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "5",
|
||||
"when": 1782374500000,
|
||||
"tag": "0014_message_templates",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"version": "5",
|
||||
"when": 1782374600000,
|
||||
"tag": "0015_group_messages",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"version": "5",
|
||||
"when": 1782445200000,
|
||||
"tag": "0018_attendance_status_reason",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 10,
|
||||
"version": "5",
|
||||
"when": 1782448800000,
|
||||
"tag": "0019_attendance_warning_thresholds",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 11,
|
||||
"version": "5",
|
||||
"when": 1782452400000,
|
||||
"tag": "0020_leave_requests",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 12,
|
||||
"version": "5",
|
||||
"when": 1782456000000,
|
||||
"tag": "0021_attendance_period",
|
||||
"when": 1783064688766,
|
||||
"tag": "0000_aberrant_deathstrike",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user