diff --git a/docs/work_log.md b/docs/work_log.md index 352278a..b44afad 100644 --- a/docs/work_log.md +++ b/docs/work_log.md @@ -1,5 +1,58 @@ # Work Log +## 2026-06-17 + +### 1. Next.js 16 Proxy 修复 +- `src/proxy.ts` 导出函数从 `middleware` 重命名为 `proxy`(Next.js 16 要求) +- 修复 `getToken()` 在 edge 运行时缺少 `secret` 导致的 `MissingSecret` 错误 +- 显式传入 `secret: process.env.NEXTAUTH_SECRET` +- 主要修改:[proxy.ts](file:///e:/Desktop/CICD/src/proxy.ts) + +### 2. MySQL 端口切换 + 数据库创建脚本 +- `.env` 中 MySQL 端口从 13002 改为 14013 +- 新增 `scripts/create-db.ts`:连接 MySQL(不指定库)后执行 `CREATE DATABASE IF NOT EXISTS next_edu`,字符集 utf8mb4_unicode_ci +- 主要修改:[.env](file:///e:/Desktop/CICD/.env)、[create-db.ts](file:///e:/Desktop/CICD/scripts/create-db.ts) + +### 3. 种子脚本完全重写(小学场景) +- 完全重写 `scripts/seed.ts`,实现小学完整场景初始化 +- 数据规模: + - 1 所学校(实验小学)、2 个年级(一/二年级)、每年级 2 个班级 + - 8 名教师(每班 2 名:1 班主任 + 1 科任,跨班覆盖语数外 3 科) + - 24 名学生(每班 6 名)+ 24 名家长 + - 3 科教材(语数外各 1 本)+ 章节 + 知识点 + - 15 道题目(每科 5 道:单选/文本/判断) + - 2 套试卷(语文/数学)+ 24 份提交 + 120 个答案 + - 2 套作业 + 6 份提交 + 30 个答案 + - 课表、成绩、考勤、课程计划、公告等完整数据 + - 6 个角色 + 47 个权限点的 RBAC 映射(149 条记录) +- 17 个顺序步骤,耗时约 127s +- 主要修改:[seed.ts](file:///e:/Desktop/CICD/scripts/seed.ts) + +### 4. 迁移脚本系统重构 +- **问题**:旧迁移系统存在多个缺陷 + - `0011_ai_providers.sql` 未在 `_journal.json` 中注册,导致 `drizzle-kit migrate` 失败 + - 缺少多数 snapshot 文件(仅存 0008、0009) + - 迁移 SQL 使用复杂 PREPARE/EXECUTE 条件模式,维护困难 +- **修复**:清理全部旧迁移文件与 meta 目录,使用 `drizzle-kit generate` 从 schema 重新生成 + - 生成单一迁移文件 `0000_perfect_pestilence.sql`,包含全部 49 张表 + - journal 重置为单条记录,snapshot 完整 +- **新增 npm 脚本**(package.json): + - `db:create`:创建数据库 + - `db:push`:直接同步 schema(开发用) + - `db:setup`:一键 create → migrate → seed +- 主要修改:[package.json](file:///e:/Desktop/CICD/package.json)、drizzle/ 目录 + +### 5. 验证 +- 干净数据库全流程测试:`db:create` → `db:migrate` → `db:seed` 全部通过 +- 49 张表成功创建,种子数据完整写入 +- 测试账号(密码均为 123456): + - 管理员: admin@xiaoxue.edu.cn + - 语文老师/一年级1班班主任: t_chinese_1@xiaoxue.edu.cn + - 数学老师: t_math_1@xiaoxue.edu.cn + - 英语老师: t_english_1@xiaoxue.edu.cn + - 学生: student_g1c1_1@xiaoxue.edu.cn + - 家长: parent_g1c1_1@xiaoxue.edu.cn + ## 2026-03-19 ### 1. 作业与权限测试覆盖补齐(第二阶段) diff --git a/drizzle/0000_aberrant_cobalt_man.sql b/drizzle/0000_aberrant_cobalt_man.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0000_aberrant_cobalt_man.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0000_perfect_pestilence.sql b/drizzle/0000_perfect_pestilence.sql new file mode 100644 index 0000000..7339a20 --- /dev/null +++ b/drizzle/0000_perfect_pestilence.sql @@ -0,0 +1,816 @@ +CREATE TABLE `academic_years` ( + `id` varchar(128) NOT NULL, + `name` varchar(100) NOT NULL, + `start_date` timestamp NOT NULL, + `end_date` timestamp NOT NULL, + `is_active` boolean NOT NULL DEFAULT false, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `academic_years_id` PRIMARY KEY(`id`), + CONSTRAINT `academic_years_name_unique` UNIQUE(`name`) +); +--> statement-breakpoint +CREATE TABLE `accounts` ( + `userId` varchar(128) NOT NULL, + `type` varchar(255) NOT NULL, + `provider` varchar(255) NOT NULL, + `providerAccountId` varchar(255) NOT NULL, + `refresh_token` text, + `access_token` text, + `expires_at` int, + `token_type` varchar(255), + `scope` varchar(255), + `id_token` text, + `session_state` varchar(255), + CONSTRAINT `accounts_provider_providerAccountId_pk` PRIMARY KEY(`provider`,`providerAccountId`) +); +--> statement-breakpoint +CREATE TABLE `ai_providers` ( + `id` varchar(128) NOT NULL, + `provider` enum('zhipu','openai','gemini','custom') NOT NULL, + `base_url` varchar(512), + `model` varchar(128) NOT NULL, + `api_key_encrypted` text NOT NULL, + `api_key_last4` varchar(4), + `is_default` boolean NOT NULL DEFAULT false, + `created_by` varchar(128), + `updated_by` varchar(128), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `ai_providers_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `announcements` ( + `id` varchar(128) NOT NULL, + `title` varchar(255) NOT NULL, + `content` text NOT NULL, + `type` enum('school','grade','class') NOT NULL DEFAULT 'school', + `status` enum('draft','published','archived') NOT NULL DEFAULT 'draft', + `target_grade_id` varchar(128), + `target_class_id` varchar(128), + `author_id` varchar(128) NOT NULL, + `published_at` datetime, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `announcements_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `attendance_records` ( + `id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `class_id` varchar(128) NOT NULL, + `schedule_id` varchar(128), + `date` date NOT NULL, + `status` enum('present','absent','late','early_leave','excused') NOT NULL, + `remark` text, + `recorded_by` varchar(128) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `attendance_records_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `attendance_rules` ( + `id` varchar(128) NOT NULL, + `class_id` varchar(128), + `late_threshold_minutes` int DEFAULT 15, + `early_leave_threshold_minutes` int DEFAULT 15, + `enable_auto_mark` boolean DEFAULT false, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `attendance_rules_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `audit_logs` ( + `id` varchar(128) NOT NULL, + `user_id` varchar(128) NOT NULL, + `user_name` varchar(255) NOT NULL, + `action` varchar(255) NOT NULL, + `module` varchar(128) NOT NULL, + `target_id` varchar(128), + `target_type` varchar(128), + `detail` text, + `ip_address` varchar(45), + `user_agent` varchar(512), + `status` enum('success','failure') NOT NULL DEFAULT 'success', + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `audit_logs_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `chapters` ( + `id` varchar(128) NOT NULL, + `textbook_id` varchar(128) NOT NULL, + `title` varchar(255) NOT NULL, + `order` int DEFAULT 0, + `parent_id` varchar(128), + `content` text, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `chapters_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `class_enrollments` ( + `class_id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `class_enrollment_status` enum('active','inactive') NOT NULL DEFAULT 'active', + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `class_enrollments_class_id_student_id_pk` PRIMARY KEY(`class_id`,`student_id`) +); +--> statement-breakpoint +CREATE TABLE `class_schedule` ( + `id` varchar(128) NOT NULL, + `class_id` varchar(128) NOT NULL, + `weekday` int NOT NULL, + `start_time` varchar(5) NOT NULL, + `end_time` varchar(5) NOT NULL, + `course` varchar(255) NOT NULL, + `location` varchar(100), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `class_schedule_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `class_subject_teachers` ( + `class_id` varchar(128) NOT NULL, + `subject_id` varchar(128) NOT NULL, + `teacher_id` varchar(128), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `class_subject_teachers_class_id_subject_id_pk` PRIMARY KEY(`class_id`,`subject_id`) +); +--> statement-breakpoint +CREATE TABLE `classes` ( + `id` varchar(128) NOT NULL, + `school_name` varchar(255), + `school_id` varchar(128), + `name` varchar(255) NOT NULL, + `grade` varchar(50) NOT NULL, + `grade_id` varchar(128), + `homeroom` varchar(50), + `room` varchar(50), + `invitation_code` varchar(6), + `teacher_id` varchar(128) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `classes_id` PRIMARY KEY(`id`), + CONSTRAINT `classes_invitation_code_unique` UNIQUE(`invitation_code`) +); +--> statement-breakpoint +CREATE TABLE `classrooms` ( + `id` varchar(128) NOT NULL, + `name` varchar(255) NOT NULL, + `building` varchar(100), + `floor` int, + `capacity` int, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `classrooms_id` PRIMARY KEY(`id`), + CONSTRAINT `classrooms_name_unique` UNIQUE(`name`) +); +--> statement-breakpoint +CREATE TABLE `course_plan_items` ( + `id` varchar(128) NOT NULL, + `plan_id` varchar(128) NOT NULL, + `week` int NOT NULL, + `topic` varchar(255) NOT NULL, + `content` text, + `hours` int NOT NULL DEFAULT 2, + `textbook_chapter` varchar(255), + `notes` text, + `is_completed` boolean NOT NULL DEFAULT false, + `completed_at` date, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `course_plan_items_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `course_plans` ( + `id` varchar(128) NOT NULL, + `class_id` varchar(128) NOT NULL, + `subject_id` varchar(128) NOT NULL, + `teacher_id` varchar(128) NOT NULL, + `academic_year_id` varchar(128), + `semester` enum('1','2') NOT NULL DEFAULT '1', + `total_hours` int NOT NULL DEFAULT 0, + `completed_hours` int NOT NULL DEFAULT 0, + `weekly_hours` int NOT NULL DEFAULT 0, + `start_date` date, + `end_date` date, + `syllabus` text, + `objectives` text, + `status` enum('planning','active','completed','paused') NOT NULL DEFAULT 'planning', + `created_by` varchar(128) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `course_plans_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `data_change_logs` ( + `id` varchar(128) NOT NULL, + `table_name` varchar(128) NOT NULL, + `record_id` varchar(128) NOT NULL, + `action` enum('create','update','delete') NOT NULL, + `old_value` text, + `new_value` text, + `changed_by` varchar(128) NOT NULL, + `changed_by_name` varchar(255) NOT NULL, + `ip_address` varchar(45), + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `data_change_logs_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `departments` ( + `id` varchar(128) NOT NULL, + `name` varchar(255) NOT NULL, + `description` text, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `departments_id` PRIMARY KEY(`id`), + CONSTRAINT `departments_name_unique` UNIQUE(`name`) +); +--> statement-breakpoint +CREATE TABLE `exam_questions` ( + `exam_id` varchar(128) NOT NULL, + `question_id` varchar(128) NOT NULL, + `score` int DEFAULT 0, + `order` int DEFAULT 0, + CONSTRAINT `exam_questions_exam_id_question_id_pk` PRIMARY KEY(`exam_id`,`question_id`) +); +--> statement-breakpoint +CREATE TABLE `exam_submissions` ( + `id` varchar(128) NOT NULL, + `exam_id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `score` int, + `status` varchar(50) DEFAULT 'started', + `submitted_at` timestamp, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `exam_submissions_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `exams` ( + `id` varchar(128) NOT NULL, + `title` varchar(255) NOT NULL, + `description` text, + `structure` json, + `creator_id` varchar(128) NOT NULL, + `subject_id` varchar(128), + `grade_id` varchar(128), + `start_time` timestamp, + `end_time` timestamp, + `status` varchar(50) DEFAULT 'draft', + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `exams_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `file_attachments` ( + `id` varchar(128) NOT NULL, + `filename` varchar(255) NOT NULL, + `original_name` varchar(255) NOT NULL, + `mime_type` varchar(128) NOT NULL, + `size` bigint NOT NULL, + `storage_path` varchar(512) NOT NULL, + `url` varchar(512), + `uploader_id` varchar(128) NOT NULL, + `target_type` varchar(128), + `target_id` varchar(128), + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `file_attachments_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `grade_records` ( + `id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `class_id` varchar(128) NOT NULL, + `subject_id` varchar(128) NOT NULL, + `exam_id` varchar(128), + `academic_year_id` varchar(128), + `title` varchar(255) NOT NULL, + `score` decimal(6,2) NOT NULL, + `full_score` decimal(6,2) NOT NULL DEFAULT '100', + `type` enum('exam','quiz','homework','other') NOT NULL DEFAULT 'exam', + `semester` enum('1','2') NOT NULL DEFAULT '1', + `recorded_by` varchar(128) NOT NULL, + `remark` text, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `grade_records_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `grades` ( + `id` varchar(128) NOT NULL, + `school_id` varchar(128) NOT NULL, + `name` varchar(100) NOT NULL, + `order` int NOT NULL DEFAULT 0, + `grade_head_id` varchar(128), + `teaching_head_id` varchar(128), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `grades_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `homework_answers` ( + `id` varchar(128) NOT NULL, + `submission_id` varchar(128) NOT NULL, + `question_id` varchar(128) NOT NULL, + `answer_content` json, + `score` int, + `feedback` text, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `homework_answers_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `homework_assignment_questions` ( + `assignment_id` varchar(128) NOT NULL, + `question_id` varchar(128) NOT NULL, + `score` int DEFAULT 0, + `order` int DEFAULT 0, + CONSTRAINT `homework_assignment_questions_assignment_id_question_id_pk` PRIMARY KEY(`assignment_id`,`question_id`) +); +--> statement-breakpoint +CREATE TABLE `homework_assignment_targets` ( + `assignment_id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `homework_assignment_targets_assignment_id_student_id_pk` PRIMARY KEY(`assignment_id`,`student_id`) +); +--> statement-breakpoint +CREATE TABLE `homework_assignments` ( + `id` varchar(128) NOT NULL, + `source_exam_id` varchar(128) NOT NULL, + `title` varchar(255) NOT NULL, + `description` text, + `structure` json, + `status` varchar(50) DEFAULT 'draft', + `creator_id` varchar(128) NOT NULL, + `available_at` timestamp, + `due_at` timestamp, + `allow_late` boolean NOT NULL DEFAULT false, + `late_due_at` timestamp, + `max_attempts` int NOT NULL DEFAULT 1, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `homework_assignments_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `homework_submissions` ( + `id` varchar(128) NOT NULL, + `assignment_id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `attempt_no` int NOT NULL DEFAULT 1, + `score` int, + `status` varchar(50) DEFAULT 'started', + `started_at` timestamp NOT NULL DEFAULT (now()), + `submitted_at` timestamp, + `is_late` boolean NOT NULL DEFAULT false, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `homework_submissions_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `knowledge_points` ( + `id` varchar(128) NOT NULL, + `name` varchar(255) NOT NULL, + `description` text, + `anchor_text` varchar(255), + `parent_id` varchar(128), + `chapter_id` varchar(128), + `level` int DEFAULT 0, + `order` int DEFAULT 0, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `knowledge_points_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `login_logs` ( + `id` varchar(128) NOT NULL, + `user_id` varchar(128), + `user_email` varchar(255) NOT NULL, + `action` enum('signin','signout','signup') NOT NULL, + `status` enum('success','failure') NOT NULL DEFAULT 'success', + `ip_address` varchar(45), + `user_agent` varchar(512), + `error_message` text, + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `login_logs_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `message_notifications` ( + `id` varchar(128) NOT NULL, + `user_id` varchar(128) NOT NULL, + `type` varchar(128) NOT NULL, + `title` varchar(255) NOT NULL, + `content` text, + `link` varchar(512), + `is_read` boolean NOT NULL DEFAULT false, + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `message_notifications_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `messages` ( + `id` varchar(128) NOT NULL, + `sender_id` varchar(128) NOT NULL, + `receiver_id` varchar(128) NOT NULL, + `subject` varchar(255), + `content` text NOT NULL, + `is_read` boolean NOT NULL DEFAULT false, + `read_at` timestamp, + `parent_message_id` varchar(128), + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `messages_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `notification_preferences` ( + `id` varchar(128) NOT NULL, + `user_id` varchar(128) NOT NULL, + `email_enabled` boolean NOT NULL DEFAULT false, + `sms_enabled` boolean NOT NULL DEFAULT false, + `push_enabled` boolean NOT NULL DEFAULT true, + `homework_notifications` boolean NOT NULL DEFAULT true, + `grade_notifications` boolean NOT NULL DEFAULT true, + `announcement_notifications` boolean NOT NULL DEFAULT true, + `message_notifications` boolean NOT NULL DEFAULT true, + `attendance_notifications` boolean NOT NULL DEFAULT true, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `notification_preferences_id` PRIMARY KEY(`id`), + CONSTRAINT `notification_preferences_user_id_unique` UNIQUE(`user_id`) +); +--> statement-breakpoint +CREATE TABLE `parent_student_relations` ( + `id` varchar(128) NOT NULL, + `parent_id` varchar(128) NOT NULL, + `student_id` varchar(128) NOT NULL, + `relation` varchar(50), + `created_at` timestamp NOT NULL DEFAULT (now()), + CONSTRAINT `parent_student_relations_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `password_security` ( + `id` varchar(128) NOT NULL, + `user_id` varchar(128) NOT NULL, + `failed_login_attempts` int NOT NULL DEFAULT 0, + `locked_until` timestamp, + `password_changed_at` timestamp NOT NULL DEFAULT (now()), + `must_change_password` boolean NOT NULL DEFAULT false, + `last_password_change` timestamp, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `password_security_id` PRIMARY KEY(`id`), + CONSTRAINT `password_security_user_id_unique` UNIQUE(`user_id`) +); +--> statement-breakpoint +CREATE TABLE `questions` ( + `id` varchar(128) NOT NULL, + `content` json NOT NULL, + `type` enum('single_choice','multiple_choice','text','judgment','composite') NOT NULL, + `difficulty` int DEFAULT 1, + `parent_id` varchar(128), + `author_id` varchar(128) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `questions_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `questions_to_knowledge_points` ( + `question_id` varchar(128) NOT NULL, + `knowledge_point_id` varchar(128) NOT NULL, + CONSTRAINT `questions_to_knowledge_points_question_id_knowledge_point_id_pk` PRIMARY KEY(`question_id`,`knowledge_point_id`) +); +--> statement-breakpoint +CREATE TABLE `role_permissions` ( + `role_id` varchar(128) NOT NULL, + `permission` varchar(100) NOT NULL, + CONSTRAINT `role_permissions_role_id_permission_pk` PRIMARY KEY(`role_id`,`permission`) +); +--> statement-breakpoint +CREATE TABLE `roles` ( + `id` varchar(128) NOT NULL, + `name` varchar(50) NOT NULL, + `description` varchar(255), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `roles_id` PRIMARY KEY(`id`), + CONSTRAINT `roles_name_unique` UNIQUE(`name`) +); +--> statement-breakpoint +CREATE TABLE `schedule_changes` ( + `id` varchar(128) NOT NULL, + `original_schedule_id` varchar(128), + `class_id` varchar(128) NOT NULL, + `original_teacher_id` varchar(128), + `substitute_teacher_id` varchar(128), + `original_date` date, + `new_date` date, + `new_start_time` varchar(10), + `new_end_time` varchar(10), + `reason` text, + `status` enum('pending','approved','rejected','completed') NOT NULL DEFAULT 'pending', + `requested_by` varchar(128) NOT NULL, + `approved_by` varchar(128), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `schedule_changes_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `scheduling_rules` ( + `id` varchar(128) NOT NULL, + `class_id` varchar(128), + `max_daily_hours` int DEFAULT 8, + `max_continuous_hours` int DEFAULT 2, + `lunch_break_start` varchar(10) DEFAULT '12:00', + `lunch_break_end` varchar(10) DEFAULT '13:00', + `morning_start` varchar(10) DEFAULT '08:00', + `afternoon_end` varchar(10) DEFAULT '17:00', + `avoid_back_to_back` boolean DEFAULT false, + `balanced_subjects` boolean DEFAULT true, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `scheduling_rules_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `schools` ( + `id` varchar(128) NOT NULL, + `name` varchar(255) NOT NULL, + `code` varchar(50), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `schools_id` PRIMARY KEY(`id`), + CONSTRAINT `schools_name_unique` UNIQUE(`name`), + CONSTRAINT `schools_code_unique` UNIQUE(`code`) +); +--> statement-breakpoint +CREATE TABLE `sessions` ( + `sessionToken` varchar(255) NOT NULL, + `userId` varchar(128) NOT NULL, + `expires` timestamp NOT NULL, + CONSTRAINT `sessions_sessionToken` PRIMARY KEY(`sessionToken`) +); +--> statement-breakpoint +CREATE TABLE `subjects` ( + `id` varchar(128) NOT NULL, + `name` varchar(100) NOT NULL, + `code` varchar(50), + `order` int DEFAULT 0, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `subjects_id` PRIMARY KEY(`id`), + CONSTRAINT `subjects_name_unique` UNIQUE(`name`), + CONSTRAINT `subjects_code_unique` UNIQUE(`code`) +); +--> statement-breakpoint +CREATE TABLE `submission_answers` ( + `id` varchar(128) NOT NULL, + `submission_id` varchar(128) NOT NULL, + `question_id` varchar(128) NOT NULL, + `answer_content` json, + `score` int, + `feedback` text, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `submission_answers_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `textbooks` ( + `id` varchar(128) NOT NULL, + `title` varchar(255) NOT NULL, + `subject` varchar(100) NOT NULL, + `grade` varchar(50), + `publisher` varchar(100), + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `textbooks_id` PRIMARY KEY(`id`) +); +--> statement-breakpoint +CREATE TABLE `users` ( + `id` varchar(128) NOT NULL, + `name` varchar(255), + `email` varchar(255) NOT NULL, + `emailVerified` timestamp, + `image` varchar(255), + `password` varchar(255), + `phone` varchar(30), + `address` varchar(255), + `gender` varchar(20), + `age` int, + `grade_id` varchar(128), + `department_id` varchar(128), + `onboarded_at` timestamp, + `birth_date` date, + `guardian_name` varchar(255), + `guardian_phone` varchar(20), + `guardian_relation` varchar(50), + `consent_accepted_at` datetime, + `created_at` timestamp NOT NULL DEFAULT (now()), + `updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP, + CONSTRAINT `users_id` PRIMARY KEY(`id`), + CONSTRAINT `users_email_unique` UNIQUE(`email`) +); +--> statement-breakpoint +CREATE TABLE `users_to_roles` ( + `user_id` varchar(128) NOT NULL, + `role_id` varchar(128) NOT NULL, + CONSTRAINT `users_to_roles_user_id_role_id_pk` PRIMARY KEY(`user_id`,`role_id`) +); +--> statement-breakpoint +CREATE TABLE `verificationTokens` ( + `identifier` varchar(255) NOT NULL, + `token` varchar(255) NOT NULL, + `expires` timestamp NOT NULL, + CONSTRAINT `verificationTokens_identifier_token_pk` PRIMARY KEY(`identifier`,`token`) +); +--> statement-breakpoint +ALTER TABLE `accounts` ADD CONSTRAINT `accounts_userId_users_id_fk` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `announcements` ADD CONSTRAINT `announcements_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_records` ADD CONSTRAINT `attendance_records_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_records` ADD CONSTRAINT `attendance_records_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_records` ADD CONSTRAINT `attendance_records_recorded_by_users_id_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_records` ADD CONSTRAINT `ar_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_records` ADD CONSTRAINT `ar_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_records` ADD CONSTRAINT `ar_rb_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_rules` ADD CONSTRAINT `attendance_rules_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `attendance_rules` ADD CONSTRAINT `atr_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `chapters` ADD CONSTRAINT `chapters_textbook_id_textbooks_id_fk` FOREIGN KEY (`textbook_id`) REFERENCES `textbooks`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `class_enrollments` ADD CONSTRAINT `ce_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `class_enrollments` ADD CONSTRAINT `ce_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `class_schedule` ADD CONSTRAINT `cs_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `class_subject_teachers_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `cst_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `cst_s_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `classes` ADD CONSTRAINT `classes_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `classes` ADD CONSTRAINT `c_s_fk` FOREIGN KEY (`school_id`) REFERENCES `schools`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `classes` ADD CONSTRAINT `c_g_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plan_items` ADD CONSTRAINT `course_plan_items_plan_id_course_plans_id_fk` FOREIGN KEY (`plan_id`) REFERENCES `course_plans`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plan_items` ADD CONSTRAINT `cpi_p_fk` FOREIGN KEY (`plan_id`) REFERENCES `course_plans`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_teacher_id_users_id_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `course_plans_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `cp_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `cp_s_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `cp_t_fk` FOREIGN KEY (`teacher_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `course_plans` ADD CONSTRAINT `cp_cb_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exam_questions` ADD CONSTRAINT `exam_questions_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exam_questions` ADD CONSTRAINT `exam_questions_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exam_submissions` ADD CONSTRAINT `exam_submissions_exam_id_exams_id_fk` FOREIGN KEY (`exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exam_submissions` ADD CONSTRAINT `exam_submissions_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exams` ADD CONSTRAINT `exams_creator_id_users_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exams` ADD CONSTRAINT `exams_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `exams` ADD CONSTRAINT `exams_grade_id_grades_id_fk` FOREIGN KEY (`grade_id`) REFERENCES `grades`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `file_attachments` ADD CONSTRAINT `file_attachments_uploader_id_users_id_fk` FOREIGN KEY (`uploader_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_subject_id_subjects_id_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `grade_records_recorded_by_users_id_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `gr_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `gr_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `gr_sub_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grade_records` ADD CONSTRAINT `gr_rb_fk` FOREIGN KEY (`recorded_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grades` ADD CONSTRAINT `g_s_fk` FOREIGN KEY (`school_id`) REFERENCES `schools`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grades` ADD CONSTRAINT `g_gh_fk` FOREIGN KEY (`grade_head_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `grades` ADD CONSTRAINT `g_th_fk` FOREIGN KEY (`teaching_head_id`) REFERENCES `users`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_answers` ADD CONSTRAINT `hw_ans_sub_fk` FOREIGN KEY (`submission_id`) REFERENCES `homework_submissions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_answers` ADD CONSTRAINT `hw_ans_q_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_assignment_questions` ADD CONSTRAINT `hw_aq_a_fk` FOREIGN KEY (`assignment_id`) REFERENCES `homework_assignments`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_assignment_questions` ADD CONSTRAINT `hw_aq_q_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_assignment_targets` ADD CONSTRAINT `hw_at_a_fk` FOREIGN KEY (`assignment_id`) REFERENCES `homework_assignments`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_assignment_targets` ADD CONSTRAINT `hw_at_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_assignments` ADD CONSTRAINT `hw_asg_exam_fk` FOREIGN KEY (`source_exam_id`) REFERENCES `exams`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_assignments` ADD CONSTRAINT `hw_asg_creator_fk` FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_submissions` ADD CONSTRAINT `hw_sub_a_fk` FOREIGN KEY (`assignment_id`) REFERENCES `homework_assignments`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `homework_submissions` ADD CONSTRAINT `hw_sub_student_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `message_notifications` ADD CONSTRAINT `message_notifications_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `messages` ADD CONSTRAINT `messages_sender_id_users_id_fk` FOREIGN KEY (`sender_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `messages` ADD CONSTRAINT `messages_receiver_id_users_id_fk` FOREIGN KEY (`receiver_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `notification_preferences` ADD CONSTRAINT `notification_preferences_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `notification_preferences` ADD CONSTRAINT `np_u_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `parent_student_relations` ADD CONSTRAINT `parent_student_relations_parent_id_users_id_fk` FOREIGN KEY (`parent_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `parent_student_relations` ADD CONSTRAINT `parent_student_relations_student_id_users_id_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `parent_student_relations` ADD CONSTRAINT `psr_p_fk` FOREIGN KEY (`parent_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `parent_student_relations` ADD CONSTRAINT `psr_s_fk` FOREIGN KEY (`student_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `password_security` ADD CONSTRAINT `password_security_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `password_security` ADD CONSTRAINT `ps_u_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `questions` ADD CONSTRAINT `questions_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `q_kp_qid_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `questions_to_knowledge_points` ADD CONSTRAINT `q_kp_kpid_fk` FOREIGN KEY (`knowledge_point_id`) REFERENCES `knowledge_points`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `role_permissions` ADD CONSTRAINT `role_permissions_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `sessions` ADD CONSTRAINT `sessions_userId_users_id_fk` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `submission_answers` ADD CONSTRAINT `submission_answers_submission_id_exam_submissions_id_fk` FOREIGN KEY (`submission_id`) REFERENCES `exam_submissions`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `submission_answers` ADD CONSTRAINT `submission_answers_question_id_questions_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `users_to_roles` ADD CONSTRAINT `users_to_roles_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE `users_to_roles` ADD CONSTRAINT `users_to_roles_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX `academic_years_name_idx` ON `academic_years` (`name`);--> statement-breakpoint +CREATE INDEX `academic_years_active_idx` ON `academic_years` (`is_active`);--> statement-breakpoint +CREATE INDEX `account_userId_idx` ON `accounts` (`userId`);--> statement-breakpoint +CREATE INDEX `ai_provider_idx` ON `ai_providers` (`provider`);--> statement-breakpoint +CREATE INDEX `ai_provider_default_idx` ON `ai_providers` (`is_default`);--> statement-breakpoint +CREATE INDEX `announcements_author_idx` ON `announcements` (`author_id`);--> statement-breakpoint +CREATE INDEX `announcements_status_idx` ON `announcements` (`status`);--> statement-breakpoint +CREATE INDEX `announcements_type_idx` ON `announcements` (`type`);--> statement-breakpoint +CREATE INDEX `announcements_target_grade_idx` ON `announcements` (`target_grade_id`);--> statement-breakpoint +CREATE INDEX `announcements_target_class_idx` ON `announcements` (`target_class_id`);--> statement-breakpoint +CREATE INDEX `attendance_records_student_idx` ON `attendance_records` (`student_id`);--> statement-breakpoint +CREATE INDEX `attendance_records_class_idx` ON `attendance_records` (`class_id`);--> statement-breakpoint +CREATE INDEX `attendance_records_date_idx` ON `attendance_records` (`date`);--> statement-breakpoint +CREATE INDEX `attendance_records_class_date_idx` ON `attendance_records` (`class_id`,`date`);--> statement-breakpoint +CREATE INDEX `attendance_records_student_date_idx` ON `attendance_records` (`student_id`,`date`);--> statement-breakpoint +CREATE INDEX `attendance_records_schedule_idx` ON `attendance_records` (`schedule_id`);--> statement-breakpoint +CREATE INDEX `attendance_records_recorded_by_idx` ON `attendance_records` (`recorded_by`);--> statement-breakpoint +CREATE INDEX `attendance_rules_class_idx` ON `attendance_rules` (`class_id`);--> statement-breakpoint +CREATE INDEX `audit_logs_user_id_idx` ON `audit_logs` (`user_id`);--> statement-breakpoint +CREATE INDEX `audit_logs_module_idx` ON `audit_logs` (`module`);--> statement-breakpoint +CREATE INDEX `audit_logs_action_idx` ON `audit_logs` (`action`);--> statement-breakpoint +CREATE INDEX `audit_logs_status_idx` ON `audit_logs` (`status`);--> statement-breakpoint +CREATE INDEX `audit_logs_created_at_idx` ON `audit_logs` (`created_at`);--> statement-breakpoint +CREATE INDEX `textbook_idx` ON `chapters` (`textbook_id`);--> statement-breakpoint +CREATE INDEX `parent_id_idx` ON `chapters` (`parent_id`);--> statement-breakpoint +CREATE INDEX `class_enrollments_class_idx` ON `class_enrollments` (`class_id`);--> statement-breakpoint +CREATE INDEX `class_enrollments_student_idx` ON `class_enrollments` (`student_id`);--> statement-breakpoint +CREATE INDEX `class_schedule_class_idx` ON `class_schedule` (`class_id`);--> statement-breakpoint +CREATE INDEX `class_schedule_class_day_idx` ON `class_schedule` (`class_id`,`weekday`);--> statement-breakpoint +CREATE INDEX `class_subject_teachers_class_idx` ON `class_subject_teachers` (`class_id`);--> statement-breakpoint +CREATE INDEX `class_subject_teachers_teacher_idx` ON `class_subject_teachers` (`teacher_id`);--> statement-breakpoint +CREATE INDEX `class_subject_teachers_subject_id_idx` ON `class_subject_teachers` (`subject_id`);--> statement-breakpoint +CREATE INDEX `classes_teacher_idx` ON `classes` (`teacher_id`);--> statement-breakpoint +CREATE INDEX `classes_grade_idx` ON `classes` (`grade`);--> statement-breakpoint +CREATE INDEX `classes_school_idx` ON `classes` (`school_id`);--> statement-breakpoint +CREATE INDEX `classes_grade_id_idx` ON `classes` (`grade_id`);--> statement-breakpoint +CREATE INDEX `classrooms_name_idx` ON `classrooms` (`name`);--> statement-breakpoint +CREATE INDEX `course_plan_items_plan_idx` ON `course_plan_items` (`plan_id`);--> statement-breakpoint +CREATE INDEX `course_plan_items_plan_week_idx` ON `course_plan_items` (`plan_id`,`week`);--> statement-breakpoint +CREATE INDEX `course_plans_class_idx` ON `course_plans` (`class_id`);--> statement-breakpoint +CREATE INDEX `course_plans_teacher_idx` ON `course_plans` (`teacher_id`);--> statement-breakpoint +CREATE INDEX `course_plans_subject_idx` ON `course_plans` (`subject_id`);--> statement-breakpoint +CREATE INDEX `course_plans_status_idx` ON `course_plans` (`status`);--> statement-breakpoint +CREATE INDEX `course_plans_class_subject_idx` ON `course_plans` (`class_id`,`subject_id`);--> statement-breakpoint +CREATE INDEX `data_change_logs_table_name_idx` ON `data_change_logs` (`table_name`);--> statement-breakpoint +CREATE INDEX `data_change_logs_record_id_idx` ON `data_change_logs` (`record_id`);--> statement-breakpoint +CREATE INDEX `data_change_logs_action_idx` ON `data_change_logs` (`action`);--> statement-breakpoint +CREATE INDEX `data_change_logs_changed_by_idx` ON `data_change_logs` (`changed_by`);--> statement-breakpoint +CREATE INDEX `data_change_logs_created_at_idx` ON `data_change_logs` (`created_at`);--> statement-breakpoint +CREATE INDEX `departments_name_idx` ON `departments` (`name`);--> statement-breakpoint +CREATE INDEX `exam_student_idx` ON `exam_submissions` (`exam_id`,`student_id`);--> statement-breakpoint +CREATE INDEX `exams_subject_idx` ON `exams` (`subject_id`);--> statement-breakpoint +CREATE INDEX `exams_grade_idx` ON `exams` (`grade_id`);--> statement-breakpoint +CREATE INDEX `file_attachments_uploader_idx` ON `file_attachments` (`uploader_id`);--> statement-breakpoint +CREATE INDEX `file_attachments_target_idx` ON `file_attachments` (`target_type`,`target_id`);--> statement-breakpoint +CREATE INDEX `file_attachments_created_at_idx` ON `file_attachments` (`created_at`);--> statement-breakpoint +CREATE INDEX `grade_records_student_idx` ON `grade_records` (`student_id`);--> statement-breakpoint +CREATE INDEX `grade_records_class_idx` ON `grade_records` (`class_id`);--> statement-breakpoint +CREATE INDEX `grade_records_subject_idx` ON `grade_records` (`subject_id`);--> statement-breakpoint +CREATE INDEX `grade_records_exam_idx` ON `grade_records` (`exam_id`);--> statement-breakpoint +CREATE INDEX `grade_records_class_subject_idx` ON `grade_records` (`class_id`,`subject_id`);--> statement-breakpoint +CREATE INDEX `grade_records_recorded_by_idx` ON `grade_records` (`recorded_by`);--> statement-breakpoint +CREATE INDEX `grades_school_idx` ON `grades` (`school_id`);--> statement-breakpoint +CREATE INDEX `grades_school_name_uniq` ON `grades` (`school_id`,`name`);--> statement-breakpoint +CREATE INDEX `grades_grade_head_idx` ON `grades` (`grade_head_id`);--> statement-breakpoint +CREATE INDEX `grades_teaching_head_idx` ON `grades` (`teaching_head_id`);--> statement-breakpoint +CREATE INDEX `hw_answer_submission_idx` ON `homework_answers` (`submission_id`);--> statement-breakpoint +CREATE INDEX `hw_answer_submission_question_idx` ON `homework_answers` (`submission_id`,`question_id`);--> statement-breakpoint +CREATE INDEX `hw_assignment_questions_assignment_idx` ON `homework_assignment_questions` (`assignment_id`);--> statement-breakpoint +CREATE INDEX `hw_assignment_targets_assignment_idx` ON `homework_assignment_targets` (`assignment_id`);--> statement-breakpoint +CREATE INDEX `hw_assignment_targets_student_idx` ON `homework_assignment_targets` (`student_id`);--> statement-breakpoint +CREATE INDEX `hw_assignment_creator_idx` ON `homework_assignments` (`creator_id`);--> statement-breakpoint +CREATE INDEX `hw_assignment_source_exam_idx` ON `homework_assignments` (`source_exam_id`);--> statement-breakpoint +CREATE INDEX `hw_assignment_status_idx` ON `homework_assignments` (`status`);--> statement-breakpoint +CREATE INDEX `hw_assignment_student_idx` ON `homework_submissions` (`assignment_id`,`student_id`);--> statement-breakpoint +CREATE INDEX `parent_id_idx` ON `knowledge_points` (`parent_id`);--> statement-breakpoint +CREATE INDEX `kp_chapter_id_idx` ON `knowledge_points` (`chapter_id`);--> statement-breakpoint +CREATE INDEX `login_logs_user_id_idx` ON `login_logs` (`user_id`);--> statement-breakpoint +CREATE INDEX `login_logs_user_email_idx` ON `login_logs` (`user_email`);--> statement-breakpoint +CREATE INDEX `login_logs_action_idx` ON `login_logs` (`action`);--> statement-breakpoint +CREATE INDEX `login_logs_status_idx` ON `login_logs` (`status`);--> statement-breakpoint +CREATE INDEX `login_logs_created_at_idx` ON `login_logs` (`created_at`);--> statement-breakpoint +CREATE INDEX `message_notifications_user_idx` ON `message_notifications` (`user_id`);--> statement-breakpoint +CREATE INDEX `message_notifications_is_read_idx` ON `message_notifications` (`is_read`);--> statement-breakpoint +CREATE INDEX `message_notifications_user_read_idx` ON `message_notifications` (`user_id`,`is_read`);--> statement-breakpoint +CREATE INDEX `message_notifications_created_at_idx` ON `message_notifications` (`created_at`);--> statement-breakpoint +CREATE INDEX `messages_sender_idx` ON `messages` (`sender_id`);--> statement-breakpoint +CREATE INDEX `messages_receiver_idx` ON `messages` (`receiver_id`);--> statement-breakpoint +CREATE INDEX `messages_is_read_idx` ON `messages` (`is_read`);--> statement-breakpoint +CREATE INDEX `messages_parent_idx` ON `messages` (`parent_message_id`);--> statement-breakpoint +CREATE INDEX `messages_receiver_read_idx` ON `messages` (`receiver_id`,`is_read`);--> statement-breakpoint +CREATE INDEX `notification_preferences_user_idx` ON `notification_preferences` (`user_id`);--> statement-breakpoint +CREATE INDEX `parent_student_relations_parent_idx` ON `parent_student_relations` (`parent_id`);--> statement-breakpoint +CREATE INDEX `parent_student_relations_student_idx` ON `parent_student_relations` (`student_id`);--> statement-breakpoint +CREATE INDEX `password_security_user_idx` ON `password_security` (`user_id`);--> statement-breakpoint +CREATE INDEX `parent_id_idx` ON `questions` (`parent_id`);--> statement-breakpoint +CREATE INDEX `author_id_idx` ON `questions` (`author_id`);--> statement-breakpoint +CREATE INDEX `kp_idx` ON `questions_to_knowledge_points` (`knowledge_point_id`);--> statement-breakpoint +CREATE INDEX `role_permissions_role_idx` ON `role_permissions` (`role_id`);--> statement-breakpoint +CREATE INDEX `schedule_changes_class_idx` ON `schedule_changes` (`class_id`);--> statement-breakpoint +CREATE INDEX `schedule_changes_status_idx` ON `schedule_changes` (`status`);--> statement-breakpoint +CREATE INDEX `schedule_changes_requested_by_idx` ON `schedule_changes` (`requested_by`);--> statement-breakpoint +CREATE INDEX `schedule_changes_original_schedule_idx` ON `schedule_changes` (`original_schedule_id`);--> statement-breakpoint +CREATE INDEX `scheduling_rules_class_idx` ON `scheduling_rules` (`class_id`);--> statement-breakpoint +CREATE INDEX `schools_name_idx` ON `schools` (`name`);--> statement-breakpoint +CREATE INDEX `schools_code_idx` ON `schools` (`code`);--> statement-breakpoint +CREATE INDEX `session_userId_idx` ON `sessions` (`userId`);--> statement-breakpoint +CREATE INDEX `subjects_name_idx` ON `subjects` (`name`);--> statement-breakpoint +CREATE INDEX `submission_idx` ON `submission_answers` (`submission_id`);--> statement-breakpoint +CREATE INDEX `email_idx` ON `users` (`email`);--> statement-breakpoint +CREATE INDEX `users_grade_id_idx` ON `users` (`grade_id`);--> statement-breakpoint +CREATE INDEX `users_department_id_idx` ON `users` (`department_id`);--> statement-breakpoint +CREATE INDEX `user_id_idx` ON `users_to_roles` (`user_id`); \ No newline at end of file diff --git a/drizzle/0001_flawless_texas_twister.sql b/drizzle/0001_flawless_texas_twister.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0001_flawless_texas_twister.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0002_equal_wolfpack.sql b/drizzle/0002_equal_wolfpack.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0002_equal_wolfpack.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0003_petite_newton_destine.sql b/drizzle/0003_petite_newton_destine.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0003_petite_newton_destine.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0004_add_chapter_content_and_kp_chapter.sql b/drizzle/0004_add_chapter_content_and_kp_chapter.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0004_add_chapter_content_and_kp_chapter.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0005_add_class_school_subject_teachers.sql b/drizzle/0005_add_class_school_subject_teachers.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0005_add_class_school_subject_teachers.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0006_faithful_king_bedlam.sql b/drizzle/0006_faithful_king_bedlam.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0006_faithful_king_bedlam.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0007_talented_bromley.sql b/drizzle/0007_talented_bromley.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0007_talented_bromley.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0008_thin_madrox.sql b/drizzle/0008_thin_madrox.sql deleted file mode 100644 index 578838d..0000000 --- a/drizzle/0008_thin_madrox.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1;--> statement-breakpoint diff --git a/drizzle/0009_smart_mephistopheles.sql b/drizzle/0009_smart_mephistopheles.sql deleted file mode 100644 index e17d3cc..0000000 --- a/drizzle/0009_smart_mephistopheles.sql +++ /dev/null @@ -1,88 +0,0 @@ -SET @has_exams_subject := ( - SELECT COUNT(*) FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'exams' - AND COLUMN_NAME = 'subject_id' -);--> statement-breakpoint -SET @sql := IF(@has_exams_subject = 0, 'ALTER TABLE `exams` ADD `subject_id` varchar(128);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_exams_grade := ( - SELECT COUNT(*) FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'exams' - AND COLUMN_NAME = 'grade_id' -);--> statement-breakpoint -SET @sql := IF(@has_exams_grade = 0, 'ALTER TABLE `exams` ADD `grade_id` varchar(128);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_kp_anchor := ( - SELECT COUNT(*) FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'knowledge_points' - AND COLUMN_NAME = 'anchor_text' -);--> statement-breakpoint -SET @sql := IF(@has_kp_anchor = 0, 'ALTER TABLE `knowledge_points` ADD `anchor_text` varchar(255);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_exams_subject_fk := ( - SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'exams' - AND CONSTRAINT_NAME = 'exams_subject_id_subjects_id_fk' - AND CONSTRAINT_TYPE = 'FOREIGN KEY' -);--> statement-breakpoint -SET @sql := IF(@has_exams_subject_fk = 0, '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;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_exams_grade_fk := ( - SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'exams' - AND CONSTRAINT_NAME = 'exams_grade_id_grades_id_fk' - AND CONSTRAINT_TYPE = 'FOREIGN KEY' -);--> statement-breakpoint -SET @sql := IF(@has_exams_grade_fk = 0, '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;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_exams_subject_idx := ( - SELECT COUNT(*) FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'exams' - AND INDEX_NAME = 'exams_subject_idx' -);--> statement-breakpoint -SET @sql := IF(@has_exams_subject_idx = 0, 'CREATE INDEX `exams_subject_idx` ON `exams` (`subject_id`);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_exams_grade_idx := ( - SELECT COUNT(*) FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'exams' - AND INDEX_NAME = 'exams_grade_idx' -);--> statement-breakpoint -SET @sql := IF(@has_exams_grade_idx = 0, 'CREATE INDEX `exams_grade_idx` ON `exams` (`grade_id`);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint -INSERT IGNORE INTO `roles` (`id`, `name`, `created_at`, `updated_at`) -SELECT UUID(), LOWER(TRIM(`role`)), NOW(), NOW() -FROM `users` -WHERE `role` IS NOT NULL AND TRIM(`role`) <> '';--> statement-breakpoint -INSERT IGNORE INTO `users_to_roles` (`user_id`, `role_id`) -SELECT `users`.`id`, `roles`.`id` -FROM `users` -INNER JOIN `roles` ON `roles`.`name` = LOWER(TRIM(`users`.`role`)) -WHERE `users`.`role` IS NOT NULL AND TRIM(`users`.`role`) <> '';--> statement-breakpoint -ALTER TABLE `users` DROP COLUMN `role`; diff --git a/drizzle/0010_subject_id_switch.sql b/drizzle/0010_subject_id_switch.sql deleted file mode 100644 index 6adebc4..0000000 --- a/drizzle/0010_subject_id_switch.sql +++ /dev/null @@ -1,110 +0,0 @@ -SET @has_subject_id := ( - SELECT COUNT(*) FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'class_subject_teachers' - AND COLUMN_NAME = 'subject_id' -);--> statement-breakpoint -SET @sql := IF(@has_subject_id = 0, 'ALTER TABLE `class_subject_teachers` ADD COLUMN `subject_id` VARCHAR(128) NULL;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -INSERT INTO `subjects` (`id`, `name`, `code`) -SELECT UUID(), '语文', 'CHINESE' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '语文' OR `code` = 'CHINESE') -UNION ALL -SELECT UUID(), '数学', 'MATH' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '数学' OR `code` = 'MATH') -UNION ALL -SELECT UUID(), '英语', 'ENG' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '英语' OR `code` = 'ENG') -UNION ALL -SELECT UUID(), '美术', 'ART' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '美术' OR `code` = 'ART') -UNION ALL -SELECT UUID(), '体育', 'PE' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '体育' OR `code` = 'PE') -UNION ALL -SELECT UUID(), '科学', 'SCI' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '科学' OR `code` = 'SCI') -UNION ALL -SELECT UUID(), '社会', 'SOC' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '社会' OR `code` = 'SOC') -UNION ALL -SELECT UUID(), '音乐', 'MUSIC' FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM `subjects` WHERE `name` = '音乐' OR `code` = 'MUSIC');--> statement-breakpoint - -SET @has_subject_col := ( - SELECT COUNT(*) FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'class_subject_teachers' - AND COLUMN_NAME = 'subject' -);--> statement-breakpoint -SET @sql := IF(@has_subject_col = 1, ' - UPDATE `class_subject_teachers` cst - JOIN `subjects` s ON ( - s.`name` = cst.`subject` - OR s.`code` = CASE cst.`subject` - WHEN ''语文'' THEN ''CHINESE'' - WHEN ''数学'' THEN ''MATH'' - WHEN ''英语'' THEN ''ENG'' - WHEN ''美术'' THEN ''ART'' - WHEN ''体育'' THEN ''PE'' - WHEN ''科学'' THEN ''SCI'' - WHEN ''社会'' THEN ''SOC'' - WHEN ''音乐'' THEN ''MUSIC'' - ELSE NULL - END - ) - SET cst.`subject_id` = s.`id` - WHERE cst.`subject_id` IS NULL; -', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @subject_id_nulls := ( - SELECT COUNT(*) FROM `class_subject_teachers` - WHERE `subject_id` IS NULL -);--> statement-breakpoint -SET @sql := IF(@subject_id_nulls = 0, 'ALTER TABLE `class_subject_teachers` MODIFY COLUMN `subject_id` VARCHAR(128) NOT NULL;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @sql := IF(@subject_id_nulls = 0, 'ALTER TABLE `class_subject_teachers` DROP PRIMARY KEY;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint -SET @sql := IF(@subject_id_nulls = 0, 'ALTER TABLE `class_subject_teachers` ADD PRIMARY KEY (`class_id`, `subject_id`);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @sql := IF(@subject_id_nulls = 0 AND @has_subject_col = 1, 'ALTER TABLE `class_subject_teachers` DROP COLUMN `subject`;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_subject_id_idx := ( - SELECT COUNT(*) FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'class_subject_teachers' - AND INDEX_NAME = 'class_subject_teachers_subject_id_idx' -);--> statement-breakpoint -SET @sql := IF(@subject_id_nulls = 0 AND @has_subject_id_idx = 0, 'CREATE INDEX `class_subject_teachers_subject_id_idx` ON `class_subject_teachers` (`subject_id`);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_subject_fk := ( - SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'class_subject_teachers' - AND CONSTRAINT_NAME = 'cst_s_fk' - AND CONSTRAINT_TYPE = 'FOREIGN KEY' -);--> statement-breakpoint -SET @sql := IF(@subject_id_nulls = 0 AND @has_subject_fk = 0, 'ALTER TABLE `class_subject_teachers` ADD CONSTRAINT `cst_s_fk` FOREIGN KEY (`subject_id`) REFERENCES `subjects`(`id`) ON DELETE CASCADE;', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt; diff --git a/drizzle/0011_ai_providers.sql b/drizzle/0011_ai_providers.sql deleted file mode 100644 index e889c2d..0000000 --- a/drizzle/0011_ai_providers.sql +++ /dev/null @@ -1,46 +0,0 @@ -SET @has_ai_providers := ( - SELECT COUNT(*) FROM information_schema.TABLES - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'ai_providers' -);--> statement-breakpoint -SET @sql := IF(@has_ai_providers = 0, ' - CREATE TABLE `ai_providers` ( - `id` varchar(128) NOT NULL, - `provider` enum(''zhipu'',''openai'',''gemini'',''custom'') NOT NULL, - `base_url` varchar(512), - `model` varchar(128) NOT NULL, - `api_key_encrypted` text NOT NULL, - `api_key_last4` varchar(4), - `is_default` boolean NOT NULL DEFAULT false, - `created_by` varchar(128), - `updated_by` varchar(128), - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) - ); -', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_ai_provider_idx := ( - SELECT COUNT(*) FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'ai_providers' - AND INDEX_NAME = 'ai_provider_idx' -);--> statement-breakpoint -SET @sql := IF(@has_ai_provider_idx = 0, 'CREATE INDEX `ai_provider_idx` ON `ai_providers` (`provider`);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint - -SET @has_ai_provider_default_idx := ( - SELECT COUNT(*) FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = DATABASE() - AND TABLE_NAME = 'ai_providers' - AND INDEX_NAME = 'ai_provider_default_idx' -);--> statement-breakpoint -SET @sql := IF(@has_ai_provider_default_idx = 0, 'CREATE INDEX `ai_provider_default_idx` ON `ai_providers` (`is_default`);', 'SELECT 1');--> statement-breakpoint -PREPARE stmt FROM @sql;--> statement-breakpoint -EXECUTE stmt;--> statement-breakpoint -DEALLOCATE PREPARE stmt;--> statement-breakpoint diff --git a/drizzle/meta/0008_snapshot.json b/drizzle/meta/0000_snapshot.json similarity index 50% rename from drizzle/meta/0008_snapshot.json rename to drizzle/meta/0000_snapshot.json index 18f0917..85f7e2f 100644 --- a/drizzle/meta/0008_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,8 +1,8 @@ { "version": "5", "dialect": "mysql", - "id": "2cf4c7e4-f538-499e-a5a5-9281d556bc9d", - "prevId": "a6d95d47-4400-464e-bc53-45735dd6e3e3", + "id": "0ec4760a-6847-43de-8c01-13cb9676df8c", + "prevId": "00000000-0000-0000-0000-000000000000", "tables": { "academic_years": { "name": "academic_years", @@ -213,6 +213,735 @@ "uniqueConstraints": {}, "checkConstraint": {} }, + "ai_providers": { + "name": "ai_providers", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "enum('zhipu','openai','gemini','custom')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_url": { + "name": "base_url", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_key_encrypted": { + "name": "api_key_encrypted", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_key_last4": { + "name": "api_key_last4", + "type": "varchar(4)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "ai_provider_idx": { + "name": "ai_provider_idx", + "columns": [ + "provider" + ], + "isUnique": false + }, + "ai_provider_default_idx": { + "name": "ai_provider_default_idx", + "columns": [ + "is_default" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ai_providers_id": { + "name": "ai_providers_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "announcements": { + "name": "announcements", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "enum('school','grade','class')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'school'" + }, + "status": { + "name": "status", + "type": "enum('draft','published','archived')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'draft'" + }, + "target_grade_id": { + "name": "target_grade_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_class_id": { + "name": "target_class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "author_id": { + "name": "author_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "published_at": { + "name": "published_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "announcements_author_idx": { + "name": "announcements_author_idx", + "columns": [ + "author_id" + ], + "isUnique": false + }, + "announcements_status_idx": { + "name": "announcements_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "announcements_type_idx": { + "name": "announcements_type_idx", + "columns": [ + "type" + ], + "isUnique": false + }, + "announcements_target_grade_idx": { + "name": "announcements_target_grade_idx", + "columns": [ + "target_grade_id" + ], + "isUnique": false + }, + "announcements_target_class_idx": { + "name": "announcements_target_class_idx", + "columns": [ + "target_class_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "announcements_author_id_users_id_fk": { + "name": "announcements_author_id_users_id_fk", + "tableFrom": "announcements", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "announcements_id": { + "name": "announcements_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "attendance_records": { + "name": "attendance_records", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "student_id": { + "name": "student_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "class_id": { + "name": "class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schedule_id": { + "name": "schedule_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "enum('present','absent','late','early_leave','excused')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "recorded_by": { + "name": "recorded_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "attendance_records_student_idx": { + "name": "attendance_records_student_idx", + "columns": [ + "student_id" + ], + "isUnique": false + }, + "attendance_records_class_idx": { + "name": "attendance_records_class_idx", + "columns": [ + "class_id" + ], + "isUnique": false + }, + "attendance_records_date_idx": { + "name": "attendance_records_date_idx", + "columns": [ + "date" + ], + "isUnique": false + }, + "attendance_records_class_date_idx": { + "name": "attendance_records_class_date_idx", + "columns": [ + "class_id", + "date" + ], + "isUnique": false + }, + "attendance_records_student_date_idx": { + "name": "attendance_records_student_date_idx", + "columns": [ + "student_id", + "date" + ], + "isUnique": false + }, + "attendance_records_schedule_idx": { + "name": "attendance_records_schedule_idx", + "columns": [ + "schedule_id" + ], + "isUnique": false + }, + "attendance_records_recorded_by_idx": { + "name": "attendance_records_recorded_by_idx", + "columns": [ + "recorded_by" + ], + "isUnique": false + } + }, + "foreignKeys": { + "attendance_records_student_id_users_id_fk": { + "name": "attendance_records_student_id_users_id_fk", + "tableFrom": "attendance_records", + "tableTo": "users", + "columnsFrom": [ + "student_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "attendance_records_class_id_classes_id_fk": { + "name": "attendance_records_class_id_classes_id_fk", + "tableFrom": "attendance_records", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "attendance_records_recorded_by_users_id_fk": { + "name": "attendance_records_recorded_by_users_id_fk", + "tableFrom": "attendance_records", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ar_c_fk": { + "name": "ar_c_fk", + "tableFrom": "attendance_records", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ar_s_fk": { + "name": "ar_s_fk", + "tableFrom": "attendance_records", + "tableTo": "users", + "columnsFrom": [ + "student_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ar_rb_fk": { + "name": "ar_rb_fk", + "tableFrom": "attendance_records", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "attendance_records_id": { + "name": "attendance_records_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "attendance_rules": { + "name": "attendance_rules", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "class_id": { + "name": "class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "late_threshold_minutes": { + "name": "late_threshold_minutes", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 15 + }, + "early_leave_threshold_minutes": { + "name": "early_leave_threshold_minutes", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 15 + }, + "enable_auto_mark": { + "name": "enable_auto_mark", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "attendance_rules_class_idx": { + "name": "attendance_rules_class_idx", + "columns": [ + "class_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "attendance_rules_class_id_classes_id_fk": { + "name": "attendance_rules_class_id_classes_id_fk", + "tableFrom": "attendance_rules", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "atr_c_fk": { + "name": "atr_c_fk", + "tableFrom": "attendance_rules", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "attendance_rules_id": { + "name": "attendance_rules_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "audit_logs": { + "name": "audit_logs", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_name": { + "name": "user_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "module": { + "name": "module", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "varchar(45)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "enum('success','failure')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'success'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "audit_logs_user_id_idx": { + "name": "audit_logs_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "audit_logs_module_idx": { + "name": "audit_logs_module_idx", + "columns": [ + "module" + ], + "isUnique": false + }, + "audit_logs_action_idx": { + "name": "audit_logs_action_idx", + "columns": [ + "action" + ], + "isUnique": false + }, + "audit_logs_status_idx": { + "name": "audit_logs_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "audit_logs_created_at_idx": { + "name": "audit_logs_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "audit_logs_id": { + "name": "audit_logs_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, "chapters": { "name": "chapters", "columns": { @@ -532,9 +1261,9 @@ "notNull": true, "autoincrement": false }, - "subject": { - "name": "subject", - "type": "enum('语文','数学','英语','美术','体育','科学','社会','音乐')", + "subject_id": { + "name": "subject_id", + "type": "varchar(128)", "primaryKey": false, "notNull": true, "autoincrement": false @@ -578,6 +1307,13 @@ "teacher_id" ], "isUnique": false + }, + "class_subject_teachers_subject_id_idx": { + "name": "class_subject_teachers_subject_id_idx", + "columns": [ + "subject_id" + ], + "isUnique": false } }, "foreignKeys": { @@ -606,14 +1342,27 @@ ], "onDelete": "cascade", "onUpdate": "no action" + }, + "cst_s_fk": { + "name": "cst_s_fk", + "tableFrom": "class_subject_teachers", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": { - "class_subject_teachers_class_id_subject_pk": { - "name": "class_subject_teachers_class_id_subject_pk", + "class_subject_teachers_class_id_subject_id_pk": { + "name": "class_subject_teachers_class_id_subject_id_pk", "columns": [ "class_id", - "subject" + "subject_id" ] } }, @@ -884,6 +1633,565 @@ }, "checkConstraint": {} }, + "course_plan_items": { + "name": "course_plan_items", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "plan_id": { + "name": "plan_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "week": { + "name": "week", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "topic": { + "name": "topic", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hours": { + "name": "hours", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 2 + }, + "textbook_chapter": { + "name": "textbook_chapter", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_completed": { + "name": "is_completed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "completed_at": { + "name": "completed_at", + "type": "date", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "course_plan_items_plan_idx": { + "name": "course_plan_items_plan_idx", + "columns": [ + "plan_id" + ], + "isUnique": false + }, + "course_plan_items_plan_week_idx": { + "name": "course_plan_items_plan_week_idx", + "columns": [ + "plan_id", + "week" + ], + "isUnique": false + } + }, + "foreignKeys": { + "course_plan_items_plan_id_course_plans_id_fk": { + "name": "course_plan_items_plan_id_course_plans_id_fk", + "tableFrom": "course_plan_items", + "tableTo": "course_plans", + "columnsFrom": [ + "plan_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cpi_p_fk": { + "name": "cpi_p_fk", + "tableFrom": "course_plan_items", + "tableTo": "course_plans", + "columnsFrom": [ + "plan_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "course_plan_items_id": { + "name": "course_plan_items_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "course_plans": { + "name": "course_plans", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "class_id": { + "name": "class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject_id": { + "name": "subject_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "teacher_id": { + "name": "teacher_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "academic_year_id": { + "name": "academic_year_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "semester": { + "name": "semester", + "type": "enum('1','2')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'1'" + }, + "total_hours": { + "name": "total_hours", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "completed_hours": { + "name": "completed_hours", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "weekly_hours": { + "name": "weekly_hours", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "syllabus": { + "name": "syllabus", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "objectives": { + "name": "objectives", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "enum('planning','active','completed','paused')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'planning'" + }, + "created_by": { + "name": "created_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "course_plans_class_idx": { + "name": "course_plans_class_idx", + "columns": [ + "class_id" + ], + "isUnique": false + }, + "course_plans_teacher_idx": { + "name": "course_plans_teacher_idx", + "columns": [ + "teacher_id" + ], + "isUnique": false + }, + "course_plans_subject_idx": { + "name": "course_plans_subject_idx", + "columns": [ + "subject_id" + ], + "isUnique": false + }, + "course_plans_status_idx": { + "name": "course_plans_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "course_plans_class_subject_idx": { + "name": "course_plans_class_subject_idx", + "columns": [ + "class_id", + "subject_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "course_plans_class_id_classes_id_fk": { + "name": "course_plans_class_id_classes_id_fk", + "tableFrom": "course_plans", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "course_plans_subject_id_subjects_id_fk": { + "name": "course_plans_subject_id_subjects_id_fk", + "tableFrom": "course_plans", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "course_plans_teacher_id_users_id_fk": { + "name": "course_plans_teacher_id_users_id_fk", + "tableFrom": "course_plans", + "tableTo": "users", + "columnsFrom": [ + "teacher_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "course_plans_created_by_users_id_fk": { + "name": "course_plans_created_by_users_id_fk", + "tableFrom": "course_plans", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cp_c_fk": { + "name": "cp_c_fk", + "tableFrom": "course_plans", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cp_s_fk": { + "name": "cp_s_fk", + "tableFrom": "course_plans", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cp_t_fk": { + "name": "cp_t_fk", + "tableFrom": "course_plans", + "tableTo": "users", + "columnsFrom": [ + "teacher_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cp_cb_fk": { + "name": "cp_cb_fk", + "tableFrom": "course_plans", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "course_plans_id": { + "name": "course_plans_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "data_change_logs": { + "name": "data_change_logs", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "table_name": { + "name": "table_name", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "record_id": { + "name": "record_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "enum('create','update','delete')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "old_value": { + "name": "old_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "new_value": { + "name": "new_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "changed_by": { + "name": "changed_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "changed_by_name": { + "name": "changed_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "varchar(45)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "data_change_logs_table_name_idx": { + "name": "data_change_logs_table_name_idx", + "columns": [ + "table_name" + ], + "isUnique": false + }, + "data_change_logs_record_id_idx": { + "name": "data_change_logs_record_id_idx", + "columns": [ + "record_id" + ], + "isUnique": false + }, + "data_change_logs_action_idx": { + "name": "data_change_logs_action_idx", + "columns": [ + "action" + ], + "isUnique": false + }, + "data_change_logs_changed_by_idx": { + "name": "data_change_logs_changed_by_idx", + "columns": [ + "changed_by" + ], + "isUnique": false + }, + "data_change_logs_created_at_idx": { + "name": "data_change_logs_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "data_change_logs_id": { + "name": "data_change_logs_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, "departments": { "name": "departments", "columns": { @@ -1302,6 +2610,415 @@ "uniqueConstraints": {}, "checkConstraint": {} }, + "file_attachments": { + "name": "file_attachments", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "filename": { + "name": "filename", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "original_name": { + "name": "original_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "storage_path": { + "name": "storage_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "uploader_id": { + "name": "uploader_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "file_attachments_uploader_idx": { + "name": "file_attachments_uploader_idx", + "columns": [ + "uploader_id" + ], + "isUnique": false + }, + "file_attachments_target_idx": { + "name": "file_attachments_target_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": false + }, + "file_attachments_created_at_idx": { + "name": "file_attachments_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "file_attachments_uploader_id_users_id_fk": { + "name": "file_attachments_uploader_id_users_id_fk", + "tableFrom": "file_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploader_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "file_attachments_id": { + "name": "file_attachments_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "grade_records": { + "name": "grade_records", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "student_id": { + "name": "student_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "class_id": { + "name": "class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject_id": { + "name": "subject_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "exam_id": { + "name": "exam_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "academic_year_id": { + "name": "academic_year_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "score": { + "name": "score", + "type": "decimal(6,2)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "full_score": { + "name": "full_score", + "type": "decimal(6,2)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'100'" + }, + "type": { + "name": "type", + "type": "enum('exam','quiz','homework','other')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'exam'" + }, + "semester": { + "name": "semester", + "type": "enum('1','2')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'1'" + }, + "recorded_by": { + "name": "recorded_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "grade_records_student_idx": { + "name": "grade_records_student_idx", + "columns": [ + "student_id" + ], + "isUnique": false + }, + "grade_records_class_idx": { + "name": "grade_records_class_idx", + "columns": [ + "class_id" + ], + "isUnique": false + }, + "grade_records_subject_idx": { + "name": "grade_records_subject_idx", + "columns": [ + "subject_id" + ], + "isUnique": false + }, + "grade_records_exam_idx": { + "name": "grade_records_exam_idx", + "columns": [ + "exam_id" + ], + "isUnique": false + }, + "grade_records_class_subject_idx": { + "name": "grade_records_class_subject_idx", + "columns": [ + "class_id", + "subject_id" + ], + "isUnique": false + }, + "grade_records_recorded_by_idx": { + "name": "grade_records_recorded_by_idx", + "columns": [ + "recorded_by" + ], + "isUnique": false + } + }, + "foreignKeys": { + "grade_records_student_id_users_id_fk": { + "name": "grade_records_student_id_users_id_fk", + "tableFrom": "grade_records", + "tableTo": "users", + "columnsFrom": [ + "student_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "grade_records_class_id_classes_id_fk": { + "name": "grade_records_class_id_classes_id_fk", + "tableFrom": "grade_records", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "grade_records_subject_id_subjects_id_fk": { + "name": "grade_records_subject_id_subjects_id_fk", + "tableFrom": "grade_records", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "grade_records_recorded_by_users_id_fk": { + "name": "grade_records_recorded_by_users_id_fk", + "tableFrom": "grade_records", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gr_c_fk": { + "name": "gr_c_fk", + "tableFrom": "grade_records", + "tableTo": "classes", + "columnsFrom": [ + "class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gr_s_fk": { + "name": "gr_s_fk", + "tableFrom": "grade_records", + "tableTo": "users", + "columnsFrom": [ + "student_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gr_sub_fk": { + "name": "gr_sub_fk", + "tableFrom": "grade_records", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gr_rb_fk": { + "name": "gr_rb_fk", + "tableFrom": "grade_records", + "tableTo": "users", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "grade_records_id": { + "name": "grade_records_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, "grades": { "name": "grades", "columns": { @@ -2147,6 +3864,792 @@ "uniqueConstraints": {}, "checkConstraint": {} }, + "login_logs": { + "name": "login_logs", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_email": { + "name": "user_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "enum('signin','signout','signup')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "enum('success','failure')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'success'" + }, + "ip_address": { + "name": "ip_address", + "type": "varchar(45)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "login_logs_user_id_idx": { + "name": "login_logs_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "login_logs_user_email_idx": { + "name": "login_logs_user_email_idx", + "columns": [ + "user_email" + ], + "isUnique": false + }, + "login_logs_action_idx": { + "name": "login_logs_action_idx", + "columns": [ + "action" + ], + "isUnique": false + }, + "login_logs_status_idx": { + "name": "login_logs_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "login_logs_created_at_idx": { + "name": "login_logs_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "login_logs_id": { + "name": "login_logs_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "message_notifications": { + "name": "message_notifications", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "link": { + "name": "link", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "message_notifications_user_idx": { + "name": "message_notifications_user_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "message_notifications_is_read_idx": { + "name": "message_notifications_is_read_idx", + "columns": [ + "is_read" + ], + "isUnique": false + }, + "message_notifications_user_read_idx": { + "name": "message_notifications_user_read_idx", + "columns": [ + "user_id", + "is_read" + ], + "isUnique": false + }, + "message_notifications_created_at_idx": { + "name": "message_notifications_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "message_notifications_user_id_users_id_fk": { + "name": "message_notifications_user_id_users_id_fk", + "tableFrom": "message_notifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "message_notifications_id": { + "name": "message_notifications_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "messages": { + "name": "messages", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sender_id": { + "name": "sender_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "receiver_id": { + "name": "receiver_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "read_at": { + "name": "read_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "parent_message_id": { + "name": "parent_message_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "messages_sender_idx": { + "name": "messages_sender_idx", + "columns": [ + "sender_id" + ], + "isUnique": false + }, + "messages_receiver_idx": { + "name": "messages_receiver_idx", + "columns": [ + "receiver_id" + ], + "isUnique": false + }, + "messages_is_read_idx": { + "name": "messages_is_read_idx", + "columns": [ + "is_read" + ], + "isUnique": false + }, + "messages_parent_idx": { + "name": "messages_parent_idx", + "columns": [ + "parent_message_id" + ], + "isUnique": false + }, + "messages_receiver_read_idx": { + "name": "messages_receiver_read_idx", + "columns": [ + "receiver_id", + "is_read" + ], + "isUnique": false + } + }, + "foreignKeys": { + "messages_sender_id_users_id_fk": { + "name": "messages_sender_id_users_id_fk", + "tableFrom": "messages", + "tableTo": "users", + "columnsFrom": [ + "sender_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "messages_receiver_id_users_id_fk": { + "name": "messages_receiver_id_users_id_fk", + "tableFrom": "messages", + "tableTo": "users", + "columnsFrom": [ + "receiver_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "messages_id": { + "name": "messages_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "notification_preferences": { + "name": "notification_preferences", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_enabled": { + "name": "email_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "sms_enabled": { + "name": "sms_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "push_enabled": { + "name": "push_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "homework_notifications": { + "name": "homework_notifications", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "grade_notifications": { + "name": "grade_notifications", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "announcement_notifications": { + "name": "announcement_notifications", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "message_notifications": { + "name": "message_notifications", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "attendance_notifications": { + "name": "attendance_notifications", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "notification_preferences_user_idx": { + "name": "notification_preferences_user_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "notification_preferences_user_id_users_id_fk": { + "name": "notification_preferences_user_id_users_id_fk", + "tableFrom": "notification_preferences", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "np_u_fk": { + "name": "np_u_fk", + "tableFrom": "notification_preferences", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "notification_preferences_id": { + "name": "notification_preferences_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": { + "notification_preferences_user_id_unique": { + "name": "notification_preferences_user_id_unique", + "columns": [ + "user_id" + ] + } + }, + "checkConstraint": {} + }, + "parent_student_relations": { + "name": "parent_student_relations", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "parent_id": { + "name": "parent_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "student_id": { + "name": "student_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "relation": { + "name": "relation", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "parent_student_relations_parent_idx": { + "name": "parent_student_relations_parent_idx", + "columns": [ + "parent_id" + ], + "isUnique": false + }, + "parent_student_relations_student_idx": { + "name": "parent_student_relations_student_idx", + "columns": [ + "student_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "parent_student_relations_parent_id_users_id_fk": { + "name": "parent_student_relations_parent_id_users_id_fk", + "tableFrom": "parent_student_relations", + "tableTo": "users", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "parent_student_relations_student_id_users_id_fk": { + "name": "parent_student_relations_student_id_users_id_fk", + "tableFrom": "parent_student_relations", + "tableTo": "users", + "columnsFrom": [ + "student_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "psr_p_fk": { + "name": "psr_p_fk", + "tableFrom": "parent_student_relations", + "tableTo": "users", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "psr_s_fk": { + "name": "psr_s_fk", + "tableFrom": "parent_student_relations", + "tableTo": "users", + "columnsFrom": [ + "student_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "parent_student_relations_id": { + "name": "parent_student_relations_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "password_security": { + "name": "password_security", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "failed_login_attempts": { + "name": "failed_login_attempts", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password_changed_at": { + "name": "password_changed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "must_change_password": { + "name": "must_change_password", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "last_password_change": { + "name": "last_password_change", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "password_security_user_idx": { + "name": "password_security_user_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "password_security_user_id_users_id_fk": { + "name": "password_security_user_id_users_id_fk", + "tableFrom": "password_security", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ps_u_fk": { + "name": "ps_u_fk", + "tableFrom": "password_security", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "password_security_id": { + "name": "password_security_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": { + "password_security_user_id_unique": { + "name": "password_security_user_id_unique", + "columns": [ + "user_id" + ] + } + }, + "checkConstraint": {} + }, "questions": { "name": "questions", "columns": { @@ -2320,6 +4823,60 @@ "uniqueConstraints": {}, "checkConstraint": {} }, + "role_permissions": { + "name": "role_permissions", + "columns": { + "role_id": { + "name": "role_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "permission": { + "name": "permission", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "role_permissions_role_idx": { + "name": "role_permissions_role_idx", + "columns": [ + "role_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "role_permissions_role_id_roles_id_fk": { + "name": "role_permissions_role_id_roles_id_fk", + "tableFrom": "role_permissions", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "role_permissions_role_id_permission_pk": { + "name": "role_permissions_role_id_permission_pk", + "columns": [ + "role_id", + "permission" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, "roles": { "name": "roles", "columns": { @@ -2382,6 +4939,281 @@ }, "checkConstraint": {} }, + "schedule_changes": { + "name": "schedule_changes", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "original_schedule_id": { + "name": "original_schedule_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "class_id": { + "name": "class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "original_teacher_id": { + "name": "original_teacher_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "substitute_teacher_id": { + "name": "substitute_teacher_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "original_date": { + "name": "original_date", + "type": "date", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "new_date": { + "name": "new_date", + "type": "date", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "new_start_time": { + "name": "new_start_time", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "new_end_time": { + "name": "new_end_time", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "enum('pending','approved','rejected','completed')", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "requested_by": { + "name": "requested_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "approved_by": { + "name": "approved_by", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "schedule_changes_class_idx": { + "name": "schedule_changes_class_idx", + "columns": [ + "class_id" + ], + "isUnique": false + }, + "schedule_changes_status_idx": { + "name": "schedule_changes_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "schedule_changes_requested_by_idx": { + "name": "schedule_changes_requested_by_idx", + "columns": [ + "requested_by" + ], + "isUnique": false + }, + "schedule_changes_original_schedule_idx": { + "name": "schedule_changes_original_schedule_idx", + "columns": [ + "original_schedule_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "schedule_changes_id": { + "name": "schedule_changes_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "scheduling_rules": { + "name": "scheduling_rules", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "class_id": { + "name": "class_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_daily_hours": { + "name": "max_daily_hours", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 8 + }, + "max_continuous_hours": { + "name": "max_continuous_hours", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 2 + }, + "lunch_break_start": { + "name": "lunch_break_start", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'12:00'" + }, + "lunch_break_end": { + "name": "lunch_break_end", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'13:00'" + }, + "morning_start": { + "name": "morning_start", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'08:00'" + }, + "afternoon_end": { + "name": "afternoon_end", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'17:00'" + }, + "avoid_back_to_back": { + "name": "avoid_back_to_back", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "balanced_subjects": { + "name": "balanced_subjects", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "scheduling_rules_class_idx": { + "name": "scheduling_rules_class_idx", + "columns": [ + "class_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "scheduling_rules_id": { + "name": "scheduling_rules_id", + "columns": [ + "id" + ] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, "schools": { "name": "schools", "columns": { @@ -2827,14 +5659,6 @@ "notNull": false, "autoincrement": false }, - "role": { - "name": "role", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'student'" - }, "password": { "name": "password", "type": "varchar(255)", @@ -2891,6 +5715,41 @@ "notNull": false, "autoincrement": false }, + "birth_date": { + "name": "birth_date", + "type": "date", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "guardian_name": { + "name": "guardian_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "guardian_phone": { + "name": "guardian_phone", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "guardian_relation": { + "name": "guardian_relation", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "consent_accepted_at": { + "name": "consent_accepted_at", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, "created_at": { "name": "created_at", "type": "timestamp", @@ -3068,4 +5927,4 @@ "tables": {}, "indexes": {} } -} +} \ No newline at end of file diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json deleted file mode 100644 index 2179b82..0000000 --- a/drizzle/meta/0009_snapshot.json +++ /dev/null @@ -1,3063 +0,0 @@ -{ - "version": "5", - "dialect": "mysql", - "id": "551f3408-945e-4f1d-984c-bfd35fe9d0ea", - "prevId": "2cf4c7e4-f538-499e-a5a5-9281d556bc9d", - "tables": { - "academic_years": { - "name": "academic_years", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "start_date": { - "name": "start_date", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "end_date": { - "name": "end_date", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "academic_years_name_idx": { - "name": "academic_years_name_idx", - "columns": [ - "name" - ], - "isUnique": false - }, - "academic_years_active_idx": { - "name": "academic_years_active_idx", - "columns": [ - "is_active" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "academic_years_id": { - "name": "academic_years_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "academic_years_name_unique": { - "name": "academic_years_name_unique", - "columns": [ - "name" - ] - } - }, - "checkConstraint": {} - }, - "accounts": { - "name": "accounts", - "columns": { - "userId": { - "name": "userId", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "account_userId_idx": { - "name": "account_userId_idx", - "columns": [ - "userId" - ], - "isUnique": false - } - }, - "foreignKeys": { - "accounts_userId_users_id_fk": { - "name": "accounts_userId_users_id_fk", - "tableFrom": "accounts", - "tableTo": "users", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "accounts_provider_providerAccountId_pk": { - "name": "accounts_provider_providerAccountId_pk", - "columns": [ - "provider", - "providerAccountId" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "chapters": { - "name": "chapters", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "textbook_id": { - "name": "textbook_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "order": { - "name": "order", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - }, - "parent_id": { - "name": "parent_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "content": { - "name": "content", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "textbook_idx": { - "name": "textbook_idx", - "columns": [ - "textbook_id" - ], - "isUnique": false - }, - "parent_id_idx": { - "name": "parent_id_idx", - "columns": [ - "parent_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "chapters_textbook_id_textbooks_id_fk": { - "name": "chapters_textbook_id_textbooks_id_fk", - "tableFrom": "chapters", - "tableTo": "textbooks", - "columnsFrom": [ - "textbook_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "chapters_id": { - "name": "chapters_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "class_enrollments": { - "name": "class_enrollments", - "columns": { - "class_id": { - "name": "class_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "student_id": { - "name": "student_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "class_enrollment_status": { - "name": "class_enrollment_status", - "type": "enum('active','inactive')", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'active'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - } - }, - "indexes": { - "class_enrollments_class_idx": { - "name": "class_enrollments_class_idx", - "columns": [ - "class_id" - ], - "isUnique": false - }, - "class_enrollments_student_idx": { - "name": "class_enrollments_student_idx", - "columns": [ - "student_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "ce_c_fk": { - "name": "ce_c_fk", - "tableFrom": "class_enrollments", - "tableTo": "classes", - "columnsFrom": [ - "class_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "ce_s_fk": { - "name": "ce_s_fk", - "tableFrom": "class_enrollments", - "tableTo": "users", - "columnsFrom": [ - "student_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "class_enrollments_class_id_student_id_pk": { - "name": "class_enrollments_class_id_student_id_pk", - "columns": [ - "class_id", - "student_id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "class_schedule": { - "name": "class_schedule", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "class_id": { - "name": "class_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "weekday": { - "name": "weekday", - "type": "int", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "start_time": { - "name": "start_time", - "type": "varchar(5)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "end_time": { - "name": "end_time", - "type": "varchar(5)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "course": { - "name": "course", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "location": { - "name": "location", - "type": "varchar(100)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "class_schedule_class_idx": { - "name": "class_schedule_class_idx", - "columns": [ - "class_id" - ], - "isUnique": false - }, - "class_schedule_class_day_idx": { - "name": "class_schedule_class_day_idx", - "columns": [ - "class_id", - "weekday" - ], - "isUnique": false - } - }, - "foreignKeys": { - "cs_c_fk": { - "name": "cs_c_fk", - "tableFrom": "class_schedule", - "tableTo": "classes", - "columnsFrom": [ - "class_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "class_schedule_id": { - "name": "class_schedule_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "class_subject_teachers": { - "name": "class_subject_teachers", - "columns": { - "class_id": { - "name": "class_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "subject": { - "name": "subject", - "type": "enum('语文','数学','英语','美术','体育','科学','社会','音乐')", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "teacher_id": { - "name": "teacher_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "class_subject_teachers_class_idx": { - "name": "class_subject_teachers_class_idx", - "columns": [ - "class_id" - ], - "isUnique": false - }, - "class_subject_teachers_teacher_idx": { - "name": "class_subject_teachers_teacher_idx", - "columns": [ - "teacher_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "class_subject_teachers_teacher_id_users_id_fk": { - "name": "class_subject_teachers_teacher_id_users_id_fk", - "tableFrom": "class_subject_teachers", - "tableTo": "users", - "columnsFrom": [ - "teacher_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "cst_c_fk": { - "name": "cst_c_fk", - "tableFrom": "class_subject_teachers", - "tableTo": "classes", - "columnsFrom": [ - "class_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "class_subject_teachers_class_id_subject_pk": { - "name": "class_subject_teachers_class_id_subject_pk", - "columns": [ - "class_id", - "subject" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "classes": { - "name": "classes", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "school_name": { - "name": "school_name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "school_id": { - "name": "school_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "grade": { - "name": "grade", - "type": "varchar(50)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "grade_id": { - "name": "grade_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "homeroom": { - "name": "homeroom", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room": { - "name": "room", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "invitation_code": { - "name": "invitation_code", - "type": "varchar(6)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "teacher_id": { - "name": "teacher_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "classes_teacher_idx": { - "name": "classes_teacher_idx", - "columns": [ - "teacher_id" - ], - "isUnique": false - }, - "classes_grade_idx": { - "name": "classes_grade_idx", - "columns": [ - "grade" - ], - "isUnique": false - }, - "classes_school_idx": { - "name": "classes_school_idx", - "columns": [ - "school_id" - ], - "isUnique": false - }, - "classes_grade_id_idx": { - "name": "classes_grade_id_idx", - "columns": [ - "grade_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "classes_teacher_id_users_id_fk": { - "name": "classes_teacher_id_users_id_fk", - "tableFrom": "classes", - "tableTo": "users", - "columnsFrom": [ - "teacher_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "c_s_fk": { - "name": "c_s_fk", - "tableFrom": "classes", - "tableTo": "schools", - "columnsFrom": [ - "school_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "c_g_fk": { - "name": "c_g_fk", - "tableFrom": "classes", - "tableTo": "grades", - "columnsFrom": [ - "grade_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "classes_id": { - "name": "classes_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "classes_invitation_code_unique": { - "name": "classes_invitation_code_unique", - "columns": [ - "invitation_code" - ] - } - }, - "checkConstraint": {} - }, - "classrooms": { - "name": "classrooms", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "building": { - "name": "building", - "type": "varchar(100)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "floor": { - "name": "floor", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "capacity": { - "name": "capacity", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "classrooms_name_idx": { - "name": "classrooms_name_idx", - "columns": [ - "name" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "classrooms_id": { - "name": "classrooms_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "classrooms_name_unique": { - "name": "classrooms_name_unique", - "columns": [ - "name" - ] - } - }, - "checkConstraint": {} - }, - "departments": { - "name": "departments", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "departments_name_idx": { - "name": "departments_name_idx", - "columns": [ - "name" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "departments_id": { - "name": "departments_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "departments_name_unique": { - "name": "departments_name_unique", - "columns": [ - "name" - ] - } - }, - "checkConstraint": {} - }, - "exam_questions": { - "name": "exam_questions", - "columns": { - "exam_id": { - "name": "exam_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "question_id": { - "name": "question_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "score": { - "name": "score", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - }, - "order": { - "name": "order", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "exam_questions_exam_id_exams_id_fk": { - "name": "exam_questions_exam_id_exams_id_fk", - "tableFrom": "exam_questions", - "tableTo": "exams", - "columnsFrom": [ - "exam_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "exam_questions_question_id_questions_id_fk": { - "name": "exam_questions_question_id_questions_id_fk", - "tableFrom": "exam_questions", - "tableTo": "questions", - "columnsFrom": [ - "question_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "exam_questions_exam_id_question_id_pk": { - "name": "exam_questions_exam_id_question_id_pk", - "columns": [ - "exam_id", - "question_id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "exam_submissions": { - "name": "exam_submissions", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "exam_id": { - "name": "exam_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "student_id": { - "name": "student_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "score": { - "name": "score", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'started'" - }, - "submitted_at": { - "name": "submitted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "exam_student_idx": { - "name": "exam_student_idx", - "columns": [ - "exam_id", - "student_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "exam_submissions_exam_id_exams_id_fk": { - "name": "exam_submissions_exam_id_exams_id_fk", - "tableFrom": "exam_submissions", - "tableTo": "exams", - "columnsFrom": [ - "exam_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "exam_submissions_student_id_users_id_fk": { - "name": "exam_submissions_student_id_users_id_fk", - "tableFrom": "exam_submissions", - "tableTo": "users", - "columnsFrom": [ - "student_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "exam_submissions_id": { - "name": "exam_submissions_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "exams": { - "name": "exams", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "structure": { - "name": "structure", - "type": "json", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "creator_id": { - "name": "creator_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "subject_id": { - "name": "subject_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "grade_id": { - "name": "grade_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "start_time": { - "name": "start_time", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "end_time": { - "name": "end_time", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'draft'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "exams_subject_idx": { - "name": "exams_subject_idx", - "columns": [ - "subject_id" - ], - "isUnique": false - }, - "exams_grade_idx": { - "name": "exams_grade_idx", - "columns": [ - "grade_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "exams_creator_id_users_id_fk": { - "name": "exams_creator_id_users_id_fk", - "tableFrom": "exams", - "tableTo": "users", - "columnsFrom": [ - "creator_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "exams_subject_id_subjects_id_fk": { - "name": "exams_subject_id_subjects_id_fk", - "tableFrom": "exams", - "tableTo": "subjects", - "columnsFrom": [ - "subject_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "exams_grade_id_grades_id_fk": { - "name": "exams_grade_id_grades_id_fk", - "tableFrom": "exams", - "tableTo": "grades", - "columnsFrom": [ - "grade_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "exams_id": { - "name": "exams_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "grades": { - "name": "grades", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "school_id": { - "name": "school_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "order": { - "name": "order", - "type": "int", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "grade_head_id": { - "name": "grade_head_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "teaching_head_id": { - "name": "teaching_head_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "grades_school_idx": { - "name": "grades_school_idx", - "columns": [ - "school_id" - ], - "isUnique": false - }, - "grades_school_name_uniq": { - "name": "grades_school_name_uniq", - "columns": [ - "school_id", - "name" - ], - "isUnique": false - }, - "grades_grade_head_idx": { - "name": "grades_grade_head_idx", - "columns": [ - "grade_head_id" - ], - "isUnique": false - }, - "grades_teaching_head_idx": { - "name": "grades_teaching_head_idx", - "columns": [ - "teaching_head_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "g_s_fk": { - "name": "g_s_fk", - "tableFrom": "grades", - "tableTo": "schools", - "columnsFrom": [ - "school_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "g_gh_fk": { - "name": "g_gh_fk", - "tableFrom": "grades", - "tableTo": "users", - "columnsFrom": [ - "grade_head_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "g_th_fk": { - "name": "g_th_fk", - "tableFrom": "grades", - "tableTo": "users", - "columnsFrom": [ - "teaching_head_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "grades_id": { - "name": "grades_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "homework_answers": { - "name": "homework_answers", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "submission_id": { - "name": "submission_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "question_id": { - "name": "question_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "answer_content": { - "name": "answer_content", - "type": "json", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "score": { - "name": "score", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "feedback": { - "name": "feedback", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "hw_answer_submission_idx": { - "name": "hw_answer_submission_idx", - "columns": [ - "submission_id" - ], - "isUnique": false - }, - "hw_answer_submission_question_idx": { - "name": "hw_answer_submission_question_idx", - "columns": [ - "submission_id", - "question_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "hw_ans_sub_fk": { - "name": "hw_ans_sub_fk", - "tableFrom": "homework_answers", - "tableTo": "homework_submissions", - "columnsFrom": [ - "submission_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "hw_ans_q_fk": { - "name": "hw_ans_q_fk", - "tableFrom": "homework_answers", - "tableTo": "questions", - "columnsFrom": [ - "question_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "homework_answers_id": { - "name": "homework_answers_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "homework_assignment_questions": { - "name": "homework_assignment_questions", - "columns": { - "assignment_id": { - "name": "assignment_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "question_id": { - "name": "question_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "score": { - "name": "score", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - }, - "order": { - "name": "order", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "hw_assignment_questions_assignment_idx": { - "name": "hw_assignment_questions_assignment_idx", - "columns": [ - "assignment_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "hw_aq_a_fk": { - "name": "hw_aq_a_fk", - "tableFrom": "homework_assignment_questions", - "tableTo": "homework_assignments", - "columnsFrom": [ - "assignment_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "hw_aq_q_fk": { - "name": "hw_aq_q_fk", - "tableFrom": "homework_assignment_questions", - "tableTo": "questions", - "columnsFrom": [ - "question_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "homework_assignment_questions_assignment_id_question_id_pk": { - "name": "homework_assignment_questions_assignment_id_question_id_pk", - "columns": [ - "assignment_id", - "question_id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "homework_assignment_targets": { - "name": "homework_assignment_targets", - "columns": { - "assignment_id": { - "name": "assignment_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "student_id": { - "name": "student_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - } - }, - "indexes": { - "hw_assignment_targets_assignment_idx": { - "name": "hw_assignment_targets_assignment_idx", - "columns": [ - "assignment_id" - ], - "isUnique": false - }, - "hw_assignment_targets_student_idx": { - "name": "hw_assignment_targets_student_idx", - "columns": [ - "student_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "hw_at_a_fk": { - "name": "hw_at_a_fk", - "tableFrom": "homework_assignment_targets", - "tableTo": "homework_assignments", - "columnsFrom": [ - "assignment_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "hw_at_s_fk": { - "name": "hw_at_s_fk", - "tableFrom": "homework_assignment_targets", - "tableTo": "users", - "columnsFrom": [ - "student_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "homework_assignment_targets_assignment_id_student_id_pk": { - "name": "homework_assignment_targets_assignment_id_student_id_pk", - "columns": [ - "assignment_id", - "student_id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "homework_assignments": { - "name": "homework_assignments", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_exam_id": { - "name": "source_exam_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "structure": { - "name": "structure", - "type": "json", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'draft'" - }, - "creator_id": { - "name": "creator_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "available_at": { - "name": "available_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "due_at": { - "name": "due_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "allow_late": { - "name": "allow_late", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": false - }, - "late_due_at": { - "name": "late_due_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "max_attempts": { - "name": "max_attempts", - "type": "int", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "hw_assignment_creator_idx": { - "name": "hw_assignment_creator_idx", - "columns": [ - "creator_id" - ], - "isUnique": false - }, - "hw_assignment_source_exam_idx": { - "name": "hw_assignment_source_exam_idx", - "columns": [ - "source_exam_id" - ], - "isUnique": false - }, - "hw_assignment_status_idx": { - "name": "hw_assignment_status_idx", - "columns": [ - "status" - ], - "isUnique": false - } - }, - "foreignKeys": { - "hw_asg_exam_fk": { - "name": "hw_asg_exam_fk", - "tableFrom": "homework_assignments", - "tableTo": "exams", - "columnsFrom": [ - "source_exam_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "hw_asg_creator_fk": { - "name": "hw_asg_creator_fk", - "tableFrom": "homework_assignments", - "tableTo": "users", - "columnsFrom": [ - "creator_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "homework_assignments_id": { - "name": "homework_assignments_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "homework_submissions": { - "name": "homework_submissions", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "assignment_id": { - "name": "assignment_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "student_id": { - "name": "student_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "attempt_no": { - "name": "attempt_no", - "type": "int", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "score": { - "name": "score", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'started'" - }, - "started_at": { - "name": "started_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "submitted_at": { - "name": "submitted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_late": { - "name": "is_late", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "hw_assignment_student_idx": { - "name": "hw_assignment_student_idx", - "columns": [ - "assignment_id", - "student_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "hw_sub_a_fk": { - "name": "hw_sub_a_fk", - "tableFrom": "homework_submissions", - "tableTo": "homework_assignments", - "columnsFrom": [ - "assignment_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "hw_sub_student_fk": { - "name": "hw_sub_student_fk", - "tableFrom": "homework_submissions", - "tableTo": "users", - "columnsFrom": [ - "student_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "homework_submissions_id": { - "name": "homework_submissions_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "knowledge_points": { - "name": "knowledge_points", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "anchor_text": { - "name": "anchor_text", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "parent_id": { - "name": "parent_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "chapter_id": { - "name": "chapter_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - }, - "order": { - "name": "order", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "parent_id_idx": { - "name": "parent_id_idx", - "columns": [ - "parent_id" - ], - "isUnique": false - }, - "kp_chapter_id_idx": { - "name": "kp_chapter_id_idx", - "columns": [ - "chapter_id" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "knowledge_points_id": { - "name": "knowledge_points_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "questions": { - "name": "questions", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "content": { - "name": "content", - "type": "json", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "enum('single_choice','multiple_choice','text','judgment','composite')", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "difficulty": { - "name": "difficulty", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 1 - }, - "parent_id": { - "name": "parent_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "author_id": { - "name": "author_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "parent_id_idx": { - "name": "parent_id_idx", - "columns": [ - "parent_id" - ], - "isUnique": false - }, - "author_id_idx": { - "name": "author_id_idx", - "columns": [ - "author_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "questions_author_id_users_id_fk": { - "name": "questions_author_id_users_id_fk", - "tableFrom": "questions", - "tableTo": "users", - "columnsFrom": [ - "author_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "questions_id": { - "name": "questions_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "questions_to_knowledge_points": { - "name": "questions_to_knowledge_points", - "columns": { - "question_id": { - "name": "question_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "knowledge_point_id": { - "name": "knowledge_point_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "kp_idx": { - "name": "kp_idx", - "columns": [ - "knowledge_point_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "q_kp_qid_fk": { - "name": "q_kp_qid_fk", - "tableFrom": "questions_to_knowledge_points", - "tableTo": "questions", - "columnsFrom": [ - "question_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "q_kp_kpid_fk": { - "name": "q_kp_kpid_fk", - "tableFrom": "questions_to_knowledge_points", - "tableTo": "knowledge_points", - "columnsFrom": [ - "knowledge_point_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "questions_to_knowledge_points_question_id_knowledge_point_id_pk": { - "name": "questions_to_knowledge_points_question_id_knowledge_point_id_pk", - "columns": [ - "question_id", - "knowledge_point_id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "roles": { - "name": "roles", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(50)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "roles_id": { - "name": "roles_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "roles_name_unique": { - "name": "roles_name_unique", - "columns": [ - "name" - ] - } - }, - "checkConstraint": {} - }, - "schools": { - "name": "schools", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "code": { - "name": "code", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "schools_name_idx": { - "name": "schools_name_idx", - "columns": [ - "name" - ], - "isUnique": false - }, - "schools_code_idx": { - "name": "schools_code_idx", - "columns": [ - "code" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "schools_id": { - "name": "schools_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "schools_name_unique": { - "name": "schools_name_unique", - "columns": [ - "name" - ] - }, - "schools_code_unique": { - "name": "schools_code_unique", - "columns": [ - "code" - ] - } - }, - "checkConstraint": {} - }, - "sessions": { - "name": "sessions", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "session_userId_idx": { - "name": "session_userId_idx", - "columns": [ - "userId" - ], - "isUnique": false - } - }, - "foreignKeys": { - "sessions_userId_users_id_fk": { - "name": "sessions_userId_users_id_fk", - "tableFrom": "sessions", - "tableTo": "users", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "sessions_sessionToken": { - "name": "sessions_sessionToken", - "columns": [ - "sessionToken" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "subjects": { - "name": "subjects", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "code": { - "name": "code", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "order": { - "name": "order", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": 0 - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "subjects_name_idx": { - "name": "subjects_name_idx", - "columns": [ - "name" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "subjects_id": { - "name": "subjects_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "subjects_name_unique": { - "name": "subjects_name_unique", - "columns": [ - "name" - ] - }, - "subjects_code_unique": { - "name": "subjects_code_unique", - "columns": [ - "code" - ] - } - }, - "checkConstraint": {} - }, - "submission_answers": { - "name": "submission_answers", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "submission_id": { - "name": "submission_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "question_id": { - "name": "question_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "answer_content": { - "name": "answer_content", - "type": "json", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "score": { - "name": "score", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "feedback": { - "name": "feedback", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "submission_idx": { - "name": "submission_idx", - "columns": [ - "submission_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "submission_answers_submission_id_exam_submissions_id_fk": { - "name": "submission_answers_submission_id_exam_submissions_id_fk", - "tableFrom": "submission_answers", - "tableTo": "exam_submissions", - "columnsFrom": [ - "submission_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submission_answers_question_id_questions_id_fk": { - "name": "submission_answers_question_id_questions_id_fk", - "tableFrom": "submission_answers", - "tableTo": "questions", - "columnsFrom": [ - "question_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "submission_answers_id": { - "name": "submission_answers_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "textbooks": { - "name": "textbooks", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "title": { - "name": "title", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "subject": { - "name": "subject", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "grade": { - "name": "grade", - "type": "varchar(50)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "publisher": { - "name": "publisher", - "type": "varchar(100)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "textbooks_id": { - "name": "textbooks_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "users": { - "name": "users", - "columns": { - "id": { - "name": "id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phone": { - "name": "phone", - "type": "varchar(30)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "address": { - "name": "address", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "gender": { - "name": "gender", - "type": "varchar(20)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "age": { - "name": "age", - "type": "int", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "grade_id": { - "name": "grade_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "department_id": { - "name": "department_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "onboarded_at": { - "name": "onboarded_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "(now())" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "onUpdate": true, - "default": "(now())" - } - }, - "indexes": { - "email_idx": { - "name": "email_idx", - "columns": [ - "email" - ], - "isUnique": false - }, - "users_grade_id_idx": { - "name": "users_grade_id_idx", - "columns": [ - "grade_id" - ], - "isUnique": false - }, - "users_department_id_idx": { - "name": "users_department_id_idx", - "columns": [ - "department_id" - ], - "isUnique": false - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": { - "users_id": { - "name": "users_id", - "columns": [ - "id" - ] - } - }, - "uniqueConstraints": { - "users_email_unique": { - "name": "users_email_unique", - "columns": [ - "email" - ] - } - }, - "checkConstraint": {} - }, - "users_to_roles": { - "name": "users_to_roles", - "columns": { - "user_id": { - "name": "user_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "role_id": { - "name": "role_id", - "type": "varchar(128)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "user_id_idx": { - "name": "user_id_idx", - "columns": [ - "user_id" - ], - "isUnique": false - } - }, - "foreignKeys": { - "users_to_roles_user_id_users_id_fk": { - "name": "users_to_roles_user_id_users_id_fk", - "tableFrom": "users_to_roles", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "users_to_roles_role_id_roles_id_fk": { - "name": "users_to_roles_role_id_roles_id_fk", - "tableFrom": "users_to_roles", - "tableTo": "roles", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "users_to_roles_user_id_role_id_pk": { - "name": "users_to_roles_user_id_role_id_pk", - "columns": [ - "user_id", - "role_id" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - }, - "verificationTokens": { - "name": "verificationTokens", - "columns": { - "identifier": { - "name": "identifier", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationTokens_identifier_token_pk": { - "name": "verificationTokens_identifier_token_pk", - "columns": [ - "identifier", - "token" - ] - } - }, - "uniqueConstraints": {}, - "checkConstraint": {} - } - }, - "views": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "tables": {}, - "indexes": {} - } -} diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 56d4b1d..e9ebd31 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -5,79 +5,9 @@ { "idx": 0, "version": "5", - "when": 1766460456274, - "tag": "0000_aberrant_cobalt_man", - "breakpoints": true - }, - { - "idx": 1, - "version": "5", - "when": 1767004087964, - "tag": "0001_flawless_texas_twister", - "breakpoints": true - }, - { - "idx": 2, - "version": "5", - "when": 1767145757594, - "tag": "0002_equal_wolfpack", - "breakpoints": true - }, - { - "idx": 3, - "version": "5", - "when": 1767166769676, - "tag": "0003_petite_newton_destine", - "breakpoints": true - }, - { - "idx": 4, - "version": "5", - "when": 1767169003334, - "tag": "0004_add_chapter_content_and_kp_chapter", - "breakpoints": true - }, - { - "idx": 5, - "version": "5", - "when": 1767751916045, - "tag": "0005_add_class_school_subject_teachers", - "breakpoints": true - }, - { - "idx": 6, - "version": "5", - "when": 1767760693171, - "tag": "0006_faithful_king_bedlam", - "breakpoints": true - }, - { - "idx": 7, - "version": "5", - "when": 1768205524480, - "tag": "0007_talented_bromley", - "breakpoints": true - }, - { - "idx": 8, - "version": "5", - "when": 1768470966367, - "tag": "0008_thin_madrox", - "breakpoints": true - }, - { - "idx": 9, - "version": "5", - "when": 1772162908476, - "tag": "0009_smart_mephistopheles", - "breakpoints": true - }, - { - "idx": 10, - "version": "5", - "when": 1772439600000, - "tag": "0010_subject_id_switch", + "when": 1781676504560, + "tag": "0000_perfect_pestilence", "breakpoints": true } ] -} +} \ No newline at end of file diff --git a/package.json b/package.json index ac227d7..40b83a3 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,12 @@ "test:e2e": "playwright test", "test:e2e:smoke": "playwright test tests/e2e/smoke-auth.spec.ts", "test:e2e:full-routes": "playwright test tests/e2e/full-route-regression.spec.ts", + "db:create": "npx tsx scripts/create-db.ts", "db:seed": "npx tsx scripts/seed.ts", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", + "db:push": "drizzle-kit push", + "db:setup": "npx tsx scripts/create-db.ts && drizzle-kit migrate && npx tsx scripts/seed.ts", "audit": "npm audit --audit-level=moderate", "audit:report": "npm audit --json > audit-report.json", "backup": "bash scripts/backup-db.sh",