Files
saqel/backend/migrations/20260908_runtime_schema_consolidation.sql
T

35 lines
1.6 KiB
SQL

-- Consolidates additive schema previously created lazily by request handlers.
-- Run once on staging/production before disabling runtime DDL.
ALTER TABLE `teachers`
ADD COLUMN `grades_taught` TEXT NULL,
ADD COLUMN `school_name` VARCHAR(255) NULL;
ALTER TABLE `exam_attempts`
ADD COLUMN `completed_at` TIMESTAMP NULL DEFAULT NULL AFTER `ai_diagnostic_report`;
CREATE TABLE IF NOT EXISTS `teacher_reviews` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`teacher_id` BIGINT UNSIGNED NOT NULL,
`student_id` BIGINT UNSIGNED NOT NULL,
`course_id` BIGINT UNSIGNED NULL,
`lesson_id` BIGINT UNSIGNED NULL,
`rating_overall` DECIMAL(3,2) NOT NULL DEFAULT 5.00,
`rating_clarity` INT NOT NULL DEFAULT 5,
`rating_response_speed` INT NOT NULL DEFAULT 5,
`rating_socratic_interaction` INT NOT NULL DEFAULT 5,
`review_text` TEXT NULL,
`review_weight` DECIMAL(4,3) NOT NULL DEFAULT 1.000,
`student_watch_percentage` DECIMAL(5,2) NOT NULL DEFAULT 100.00,
`socratic_accuracy_rate` DECIMAL(5,2) NOT NULL DEFAULT 100.00,
`is_flagged_anomaly` TINYINT(1) NOT NULL DEFAULT 0,
`is_verified` TINYINT(1) NOT NULL DEFAULT 1,
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_teacher_reviews_teacher` (`teacher_id`),
KEY `idx_teacher_reviews_student` (`student_id`),
CONSTRAINT `fk_tr_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teachers` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_tr_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;