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','ollama') 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,
	`visibility` enum('public','private') NOT NULL DEFAULT 'private',
	`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 `announcement_reads` (
	`id` varchar(128) NOT NULL,
	`announcement_id` varchar(128) NOT NULL,
	`user_id` varchar(128) NOT NULL,
	`read_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `announcement_reads_id` PRIMARY KEY(`id`),
	CONSTRAINT `announcement_reads_unique_idx` UNIQUE(`announcement_id`,`user_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,
	`is_pinned` boolean NOT NULL DEFAULT false,
	`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','school_activity') NOT NULL,
	`period` enum('morning_reading','morning','afternoon','evening','full_day'),
	`remark` text,
	`reason` varchar(255),
	`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,
	`attendance_rate_threshold` int DEFAULT 90,
	`consecutive_absence_threshold` int DEFAULT 3,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL 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_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 `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 `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,
	`drop_reason` varchar(255),
	`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 `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 `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,
	`drop_deadline` 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 `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
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 `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,
	`exam_mode` enum('homework','timed','proctored') DEFAULT 'homework',
	`duration_minutes` int,
	`shuffle_questions` boolean DEFAULT false,
	`allow_late_start` boolean DEFAULT false,
	`late_start_grace_minutes` int DEFAULT 0,
	`anti_cheat_enabled` boolean DEFAULT false,
	`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_appeals` (
	`id` varchar(128) NOT NULL,
	`grade_record_id` varchar(128) NOT NULL,
	`student_id` varchar(128) NOT NULL,
	`original_score` decimal(6,2) NOT NULL,
	`expected_score` decimal(6,2),
	`reason` text NOT NULL,
	`appeal_status` enum('pending','approved','rejected','withdrawn') NOT NULL DEFAULT 'pending',
	`reviewer_id` varchar(128),
	`review_comment` text,
	`adjusted_score` decimal(6,2),
	`reviewed_at` timestamp,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `grade_appeals_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `grade_drafts` (
	`id` varchar(128) NOT NULL,
	`user_id` varchar(128) NOT NULL,
	`class_id` varchar(128) NOT NULL,
	`subject_id` varchar(128) NOT NULL,
	`type` varchar(20) NOT NULL,
	`content` json NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`locked_by` varchar(128),
	`locked_at` timestamp,
	`lock_token` varchar(64),
	CONSTRAINT `grade_drafts_id` PRIMARY KEY(`id`),
	CONSTRAINT `gd_user_class_subject_type_idx` UNIQUE(`user_id`,`class_id`,`subject_id`,`type`)
);
--> statement-breakpoint
CREATE TABLE `grade_record_answers` (
	`id` varchar(128) 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 NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `grade_record_answers_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),
	`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 `invitation_codes` (
	`id` varchar(128) NOT NULL,
	`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 (now()),
	`created_by` varchar(128),
	`expires_at` timestamp,
	`used_by` varchar(128),
	`used_at` timestamp,
	CONSTRAINT `invitation_codes_id` PRIMARY KEY(`id`),
	CONSTRAINT `invitation_codes_code_unique` UNIQUE(`code`)
);
--> 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 `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 `kp_prereq_pk` PRIMARY KEY(`knowledge_point_id`,`prerequisite_kp_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 `learning_diagnostic_reports` (
	`id` varchar(128) NOT NULL,
	`student_id` varchar(128),
	`generated_by` varchar(128),
	`class_id` varchar(128),
	`grade_id` 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
CREATE TABLE `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,
	`leave_status` enum('pending','approved','rejected','cancelled') NOT NULL DEFAULT 'pending',
	`reviewer_id` varchar(128),
	`review_comment` text,
	`reviewed_at` timestamp,
	`attendance_synced` boolean NOT NULL DEFAULT false,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `leave_requests_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_ai_evaluations` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`version_no` int NOT NULL,
	`overall_score` int,
	`dimension_scores` json,
	`suggestions` text,
	`recommended_standard_ids` json,
	`evaluated_by` varchar(128) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `lesson_plan_ai_evaluations_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_analytics_daily` (
	`id` varchar(128) NOT NULL,
	`snapshot_date` date NOT NULL,
	`teacher_id` varchar(128) NOT NULL,
	`subject_id` varchar(128),
	`grade_id` varchar(128),
	`new_plans_count` int NOT NULL DEFAULT 0,
	`edit_duration_min` int NOT NULL DEFAULT 0,
	`saved_versions_count` int NOT NULL DEFAULT 0,
	`submitted_count` int NOT NULL DEFAULT 0,
	`published_count` int NOT NULL DEFAULT 0,
	`standards_linked` int NOT NULL DEFAULT 0,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `lesson_plan_analytics_daily_id` PRIMARY KEY(`id`),
	CONSTRAINT `lpad_date_teacher_idx` UNIQUE(`snapshot_date`,`teacher_id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_attachments` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`block_id` varchar(128),
	`file_id` varchar(128) NOT NULL,
	`display_name` varchar(255) NOT NULL,
	`attachment_type` varchar(50) NOT NULL DEFAULT 'reference',
	`uploaded_by` varchar(128) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `lesson_plan_attachments_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_comments` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`block_id` varchar(128) NOT NULL,
	`content` text NOT NULL,
	`author_id` varchar(128) NOT NULL,
	`resolved` boolean NOT NULL DEFAULT false,
	`parent_comment_id` varchar(128),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `lesson_plan_comments_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_formative_items` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`block_id` varchar(128) NOT NULL,
	`interaction_type` varchar(20) NOT NULL,
	`payload` json NOT NULL,
	`instant_feedback` boolean NOT NULL DEFAULT false,
	`order_index` int NOT NULL DEFAULT 0,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `lesson_plan_formative_items_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_formative_responses` (
	`id` varchar(128) NOT NULL,
	`item_id` varchar(128) NOT NULL,
	`student_id` varchar(128) NOT NULL,
	`class_id` varchar(128),
	`response` json NOT NULL,
	`is_correct` boolean,
	`duration_sec` int,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `lesson_plan_formative_responses_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_review_records` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`reviewer_id` varchar(128) NOT NULL,
	`decision` varchar(20) NOT NULL,
	`comment` text,
	`previous_status` varchar(50) NOT NULL,
	`new_status` varchar(50) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `lesson_plan_review_records_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_standards` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`standard_id` varchar(128) NOT NULL,
	`relation_type` varchar(20) NOT NULL DEFAULT 'primary',
	`created_by` varchar(128) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `lesson_plan_standards_id` PRIMARY KEY(`id`),
	CONSTRAINT `lps_plan_standard_idx` UNIQUE(`plan_id`,`standard_id`)
);
--> statement-breakpoint
CREATE TABLE `lesson_plan_substitutes` (
	`id` varchar(128) NOT NULL,
	`plan_id` varchar(128) NOT NULL,
	`original_teacher_id` varchar(128) NOT NULL,
	`substitute_teacher_id` varchar(128) NOT NULL,
	`start_date` date NOT NULL,
	`end_date` date,
	`reason` varchar(255),
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`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 `lesson_plan_substitutes_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
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
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_drafts` (
	`id` varchar(128) NOT NULL,
	`user_id` varchar(128) NOT NULL,
	`receiver_id` varchar(128),
	`subject` varchar(255),
	`content` text,
	`parent_message_id` varchar(128),
	`device_id` varchar(128),
	`version` int NOT NULL DEFAULT 1,
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `message_drafts_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,
	`priority` varchar(16) NOT NULL DEFAULT 'normal',
	`is_archived` boolean NOT NULL DEFAULT false,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `message_notifications_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
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 (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `message_reports_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `message_templates` (
	`id` varchar(128) NOT NULL,
	`user_id` varchar(128) NOT NULL,
	`title` varchar(100) NOT NULL,
	`content` text NOT NULL,
	`sort_order` int NOT NULL DEFAULT 0,
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `message_templates_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),
	`sender_deleted_at` timestamp,
	`receiver_deleted_at` timestamp,
	`is_starred` boolean NOT NULL DEFAULT false,
	`recalled_at` timestamp,
	`group_message_id` varchar(128),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `messages_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `notification_logs` (
	`id` varchar(128) 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 NOT NULL DEFAULT (now()),
	CONSTRAINT `notification_logs_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,
	`quiet_hours_enabled` boolean NOT NULL DEFAULT false,
	`quiet_hours_start` varchar(5),
	`quiet_hours_end` varchar(5),
	`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 `practice_answers` (
	`id` varchar(128) NOT NULL,
	`session_id` varchar(128) NOT NULL,
	`student_id` varchar(128) NOT NULL,
	`question_id` varchar(128) NOT NULL,
	`variant_content` json,
	`is_variant` boolean NOT NULL DEFAULT false,
	`order_index` int NOT NULL,
	`practice_answer_status` enum('pending','answered','skipped') NOT NULL DEFAULT 'pending',
	`student_answer` json,
	`is_correct` boolean,
	`score` int,
	`max_score` int NOT NULL DEFAULT 1,
	`answered_at` timestamp,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `practice_answers_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `practice_sessions` (
	`id` varchar(128) NOT NULL,
	`student_id` varchar(128) NOT NULL,
	`subject_id` varchar(128),
	`practice_type` enum('error_variant','knowledge_point','weak_chapter','ai_recommended') NOT NULL,
	`source_meta` json,
	`practice_status` enum('in_progress','completed','abandoned') NOT NULL DEFAULT 'in_progress',
	`total_questions` int NOT NULL DEFAULT 0,
	`answered_questions` int NOT NULL DEFAULT 0,
	`correct_count` int NOT NULL DEFAULT 0,
	`started_at` timestamp NOT NULL DEFAULT (now()),
	`completed_at` timestamp,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `practice_sessions_id` PRIMARY KEY(`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),
	`is_system` boolean NOT NULL DEFAULT false,
	`is_enabled` boolean NOT NULL DEFAULT true,
	`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 `standards` (
	`id` varchar(128) NOT NULL,
	`code` varchar(100) NOT NULL,
	`title` varchar(255) NOT NULL,
	`description` text,
	`level` varchar(20) NOT NULL,
	`parent_id` varchar(128),
	`subject_id` varchar(128),
	`grade_id` varchar(128),
	`stage` varchar(20),
	`sort_order` int NOT NULL DEFAULT 0,
	`is_active` boolean NOT NULL DEFAULT true,
	`created_by` varchar(128),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `standards_id` PRIMARY KEY(`id`),
	CONSTRAINT `std_code_idx` UNIQUE(`code`)
);
--> 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 `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
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 `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 (now()),
	CONSTRAINT `user_blocks_id` PRIMARY KEY(`id`),
	CONSTRAINT `user_blocks_blocker_blocked_uniq` UNIQUE(`blocker_id`,`blocked_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 `announcement_reads` ADD CONSTRAINT `announcement_reads_announcement_id_announcements_id_fk` FOREIGN KEY (`announcement_id`) REFERENCES `announcements`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `announcement_reads` ADD CONSTRAINT `announcement_reads_user_id_users_id_fk` FOREIGN KEY (`user_id`) 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_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
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 `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 `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
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 `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_appeals` ADD CONSTRAINT `grade_appeals_grade_record_id_grade_records_id_fk` FOREIGN KEY (`grade_record_id`) REFERENCES `grade_records`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_appeals` ADD CONSTRAINT `grade_appeals_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_appeals` ADD CONSTRAINT `grade_appeals_reviewer_id_users_id_fk` FOREIGN KEY (`reviewer_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_drafts` ADD CONSTRAINT `grade_drafts_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_drafts` ADD CONSTRAINT `grade_drafts_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_drafts` ADD CONSTRAINT `grade_drafts_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_record_answers` ADD CONSTRAINT `grade_record_answers_grade_record_id_grade_records_id_fk` FOREIGN KEY (`grade_record_id`) REFERENCES `grade_records`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_record_answers` ADD CONSTRAINT `grade_record_answers_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_record_answers` ADD CONSTRAINT `gra_gr_fk` FOREIGN KEY (`grade_record_id`) REFERENCES `grade_records`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `grade_record_answers` ADD CONSTRAINT `gra_q_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`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 `knowledge_point_mastery` ADD CONSTRAINT `kpm_student_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `knowledge_point_mastery` ADD CONSTRAINT `kpm_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_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
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
ALTER TABLE `learning_diagnostic_reports` ADD CONSTRAINT `learning_diagnostic_reports_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE set null ON UPDATE no action;--> 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
ALTER TABLE `leave_requests` ADD CONSTRAINT `leave_requests_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `leave_requests_requester_id_users_id_fk` FOREIGN KEY (`requester_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `leave_requests_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `leave_requests_reviewer_id_users_id_fk` FOREIGN KEY (`reviewer_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `lr_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `lr_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `lr_rq_fk` FOREIGN KEY (`requester_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `leave_requests` ADD CONSTRAINT `lr_rv_fk` FOREIGN KEY (`reviewer_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_ai_evaluations` ADD CONSTRAINT `lesson_plan_ai_evaluations_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_analytics_daily` ADD CONSTRAINT `lesson_plan_analytics_daily_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_attachments` ADD CONSTRAINT `lesson_plan_attachments_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_attachments` ADD CONSTRAINT `lesson_plan_attachments_uploaded_by_users_id_fk` FOREIGN KEY (`uploaded_by`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_comments` ADD CONSTRAINT `lesson_plan_comments_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_comments` ADD CONSTRAINT `lesson_plan_comments_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_formative_items` ADD CONSTRAINT `lesson_plan_formative_items_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_formative_responses` ADD CONSTRAINT `lesson_plan_formative_responses_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_formative_responses` ADD CONSTRAINT `lpfr_item_fk` FOREIGN KEY (`item_id`) REFERENCES `lesson_plan_formative_items`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_review_records` ADD CONSTRAINT `lesson_plan_review_records_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_review_records` ADD CONSTRAINT `lesson_plan_review_records_reviewer_id_users_id_fk` FOREIGN KEY (`reviewer_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_standards` ADD CONSTRAINT `lesson_plan_standards_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_standards` ADD CONSTRAINT `lesson_plan_standards_standard_id_standards_id_fk` FOREIGN KEY (`standard_id`) REFERENCES `standards`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_standards` ADD CONSTRAINT `lesson_plan_standards_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_substitutes` ADD CONSTRAINT `lesson_plan_substitutes_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_substitutes` ADD CONSTRAINT `lesson_plan_substitutes_original_teacher_id_users_id_fk` FOREIGN KEY (`original_teacher_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_substitutes` ADD CONSTRAINT `lesson_plan_substitutes_substitute_teacher_id_users_id_fk` FOREIGN KEY (`substitute_teacher_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `lesson_plan_substitutes` ADD CONSTRAINT `lesson_plan_substitutes_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> 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
ALTER TABLE `message_drafts` ADD CONSTRAINT `message_drafts_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `message_drafts` ADD CONSTRAINT `message_drafts_receiver_id_users_id_fk` FOREIGN KEY (`receiver_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 `message_reports` ADD CONSTRAINT `message_reports_reporter_id_users_id_fk` FOREIGN KEY (`reporter_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `message_reports` ADD CONSTRAINT `message_reports_message_id_messages_id_fk` FOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `message_reports` ADD CONSTRAINT `message_reports_reported_user_id_users_id_fk` FOREIGN KEY (`reported_user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `message_templates` ADD CONSTRAINT `message_templates_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_logs` ADD CONSTRAINT `notification_logs_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 `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 `practice_answers` ADD CONSTRAINT `practice_answers_session_id_practice_sessions_id_fk` FOREIGN KEY (`session_id`) REFERENCES `practice_sessions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `practice_answers` ADD CONSTRAINT `practice_answers_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `practice_answers` ADD CONSTRAINT `practice_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 `practice_sessions` ADD CONSTRAINT `practice_sessions_student_id_users_id_fk` FOREIGN KEY (`student_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 `standards` ADD CONSTRAINT `standards_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `standards` ADD CONSTRAINT `standards_grade_id_grades_id_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `standards` ADD CONSTRAINT `standards_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE no action 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 `user_blocks` ADD CONSTRAINT `user_blocks_blocker_id_users_id_fk` FOREIGN KEY (`blocker_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `user_blocks` ADD CONSTRAINT `user_blocks_blocked_id_users_id_fk` FOREIGN KEY (`blocked_id`) REFERENCES `users`(`id`) ON DELETE cascade 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 `ai_provider_visibility_idx` ON `ai_providers` (`visibility`);--> statement-breakpoint
CREATE INDEX `ai_provider_created_by_idx` ON `ai_providers` (`created_by`);--> statement-breakpoint
CREATE INDEX `announcement_reads_announcement_idx` ON `announcement_reads` (`announcement_id`);--> statement-breakpoint
CREATE INDEX `announcement_reads_user_idx` ON `announcement_reads` (`user_id`);--> 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 `announcements_status_pinned_idx` ON `announcements` (`status`,`is_pinned`);--> 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_records_class_date_period_idx` ON `attendance_records` (`class_id`,`date`,`period`);--> 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_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 `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 `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 `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 `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 `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`);--> 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 `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 `ga_grade_record_idx` ON `grade_appeals` (`grade_record_id`);--> statement-breakpoint
CREATE INDEX `ga_student_idx` ON `grade_appeals` (`student_id`);--> statement-breakpoint
CREATE INDEX `ga_status_idx` ON `grade_appeals` (`appeal_status`);--> statement-breakpoint
CREATE INDEX `ga_reviewer_idx` ON `grade_appeals` (`reviewer_id`);--> statement-breakpoint
CREATE INDEX `ga_pending_lookup_idx` ON `grade_appeals` (`grade_record_id`,`appeal_status`);--> statement-breakpoint
CREATE INDEX `gd_user_updated_idx` ON `grade_drafts` (`user_id`,`updated_at`);--> statement-breakpoint
CREATE INDEX `gd_class_subject_lock_idx` ON `grade_drafts` (`class_id`,`subject_id`,`type`,`locked_by`);--> statement-breakpoint
CREATE INDEX `grade_record_answers_record_idx` ON `grade_record_answers` (`grade_record_id`);--> statement-breakpoint
CREATE INDEX `grade_record_answers_question_idx` ON `grade_record_answers` (`question_id`);--> 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 `invitation_codes_code_idx` ON `invitation_codes` (`code`);--> statement-breakpoint
CREATE INDEX `invitation_codes_email_idx` ON `invitation_codes` (`email`);--> statement-breakpoint
CREATE INDEX `invitation_codes_used_by_idx` ON `invitation_codes` (`used_by`);--> 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 `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`);--> 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 `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`);--> statement-breakpoint
CREATE INDEX `diagnostic_class_idx` ON `learning_diagnostic_reports` (`class_id`);--> statement-breakpoint
CREATE INDEX `diagnostic_grade_idx` ON `learning_diagnostic_reports` (`grade_id`);--> statement-breakpoint
CREATE INDEX `leave_requests_student_idx` ON `leave_requests` (`student_id`);--> statement-breakpoint
CREATE INDEX `leave_requests_requester_idx` ON `leave_requests` (`requester_id`);--> statement-breakpoint
CREATE INDEX `leave_requests_class_idx` ON `leave_requests` (`class_id`);--> statement-breakpoint
CREATE INDEX `leave_requests_status_idx` ON `leave_requests` (`leave_status`);--> statement-breakpoint
CREATE INDEX `leave_requests_reviewer_idx` ON `leave_requests` (`reviewer_id`);--> statement-breakpoint
CREATE INDEX `leave_requests_class_status_idx` ON `leave_requests` (`class_id`,`leave_status`);--> statement-breakpoint
CREATE INDEX `leave_requests_student_status_idx` ON `leave_requests` (`student_id`,`leave_status`);--> statement-breakpoint
CREATE INDEX `lpae_plan_version_idx` ON `lesson_plan_ai_evaluations` (`plan_id`,`version_no`);--> statement-breakpoint
CREATE INDEX `lpae_plan_idx` ON `lesson_plan_ai_evaluations` (`plan_id`);--> statement-breakpoint
CREATE INDEX `lpad_date_idx` ON `lesson_plan_analytics_daily` (`snapshot_date`);--> statement-breakpoint
CREATE INDEX `lpad_subject_grade_idx` ON `lesson_plan_analytics_daily` (`subject_id`,`grade_id`);--> statement-breakpoint
CREATE INDEX `lpa_plan_idx` ON `lesson_plan_attachments` (`plan_id`);--> statement-breakpoint
CREATE INDEX `lpa_block_idx` ON `lesson_plan_attachments` (`block_id`);--> statement-breakpoint
CREATE INDEX `lpa_file_idx` ON `lesson_plan_attachments` (`file_id`);--> statement-breakpoint
CREATE INDEX `lpc_plan_block_idx` ON `lesson_plan_comments` (`plan_id`,`block_id`);--> statement-breakpoint
CREATE INDEX `lpc_author_idx` ON `lesson_plan_comments` (`author_id`);--> statement-breakpoint
CREATE INDEX `lpfi_plan_block_idx` ON `lesson_plan_formative_items` (`plan_id`,`block_id`);--> statement-breakpoint
CREATE INDEX `lpfr_item_idx` ON `lesson_plan_formative_responses` (`item_id`);--> statement-breakpoint
CREATE INDEX `lpfr_student_idx` ON `lesson_plan_formative_responses` (`student_id`);--> statement-breakpoint
CREATE INDEX `lpfr_class_idx` ON `lesson_plan_formative_responses` (`class_id`);--> statement-breakpoint
CREATE INDEX `lprr_plan_created_idx` ON `lesson_plan_review_records` (`plan_id`,`created_at`);--> statement-breakpoint
CREATE INDEX `lprr_reviewer_idx` ON `lesson_plan_review_records` (`reviewer_id`);--> statement-breakpoint
CREATE INDEX `lps_standard_idx` ON `lesson_plan_standards` (`standard_id`);--> statement-breakpoint
CREATE INDEX `lps_plan_idx` ON `lesson_plan_substitutes` (`plan_id`);--> statement-breakpoint
CREATE INDEX `lps_original_teacher_idx` ON `lesson_plan_substitutes` (`original_teacher_id`);--> statement-breakpoint
CREATE INDEX `lps_substitute_teacher_idx` ON `lesson_plan_substitutes` (`substitute_teacher_id`);--> statement-breakpoint
CREATE INDEX `lps_date_range_idx` ON `lesson_plan_substitutes` (`start_date`,`end_date`);--> 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`);--> 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_drafts_user_idx` ON `message_drafts` (`user_id`);--> statement-breakpoint
CREATE INDEX `message_drafts_user_updated_idx` ON `message_drafts` (`user_id`,`updated_at`);--> statement-breakpoint
CREATE INDEX `message_drafts_user_parent_idx` ON `message_drafts` (`user_id`,`parent_message_id`);--> 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 `message_notifications_priority_idx` ON `message_notifications` (`priority`);--> statement-breakpoint
CREATE INDEX `message_notifications_user_archived_idx` ON `message_notifications` (`user_id`,`is_archived`);--> statement-breakpoint
CREATE INDEX `message_reports_reporter_idx` ON `message_reports` (`reporter_id`);--> statement-breakpoint
CREATE INDEX `message_reports_message_idx` ON `message_reports` (`message_id`);--> statement-breakpoint
CREATE INDEX `message_reports_reported_user_idx` ON `message_reports` (`reported_user_id`);--> statement-breakpoint
CREATE INDEX `message_reports_status_idx` ON `message_reports` (`status`);--> statement-breakpoint
CREATE INDEX `message_templates_user_idx` ON `message_templates` (`user_id`);--> statement-breakpoint
CREATE INDEX `message_templates_user_sort_idx` ON `message_templates` (`user_id`,`sort_order`);--> 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 `messages_receiver_starred_idx` ON `messages` (`receiver_id`,`is_starred`);--> statement-breakpoint
CREATE INDEX `messages_group_message_idx` ON `messages` (`group_message_id`);--> statement-breakpoint
CREATE INDEX `notification_logs_user_idx` ON `notification_logs` (`user_id`);--> statement-breakpoint
CREATE INDEX `notification_logs_channel_idx` ON `notification_logs` (`channel`);--> statement-breakpoint
CREATE INDEX `notification_logs_status_idx` ON `notification_logs` (`status`);--> statement-breakpoint
CREATE INDEX `notification_logs_sent_at_idx` ON `notification_logs` (`sent_at`);--> 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 `pa_session_idx` ON `practice_answers` (`session_id`);--> statement-breakpoint
CREATE INDEX `pa_student_idx` ON `practice_answers` (`student_id`);--> statement-breakpoint
CREATE INDEX `pa_question_idx` ON `practice_answers` (`question_id`);--> statement-breakpoint
CREATE INDEX `pa_session_order_idx` ON `practice_answers` (`session_id`,`order_index`);--> statement-breakpoint
CREATE INDEX `ps_student_idx` ON `practice_sessions` (`student_id`);--> statement-breakpoint
CREATE INDEX `ps_student_status_idx` ON `practice_sessions` (`student_id`,`practice_status`);--> statement-breakpoint
CREATE INDEX `ps_subject_idx` ON `practice_sessions` (`subject_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 `std_parent_idx` ON `standards` (`parent_id`);--> statement-breakpoint
CREATE INDEX `std_subject_grade_idx` ON `standards` (`subject_id`,`grade_id`);--> statement-breakpoint
CREATE INDEX `std_level_idx` ON `standards` (`level`);--> 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 `ss_category_idx` ON `system_settings` (`category`);--> statement-breakpoint
CREATE INDEX `user_blocks_blocker_idx` ON `user_blocks` (`blocker_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`);