Make legacy migrations safe on canonical schema
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
-- 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,
|
||||
@@ -31,4 +24,3 @@ CREATE TABLE IF NOT EXISTS `teacher_reviews` (
|
||||
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;
|
||||
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
ALTER TABLE `students`
|
||||
DROP INDEX `national_id`,
|
||||
DROP INDEX `idx_students_national_id`,
|
||||
MODIFY `national_id` TEXT NOT NULL,
|
||||
ADD COLUMN `national_id_hash` CHAR(64) NULL AFTER `national_id`,
|
||||
ADD INDEX `idx_students_national_id_hash` (`national_id_hash`),
|
||||
MODIFY `readiness_score` DECIMAL(5,2) NOT NULL DEFAULT 0.00;
|
||||
|
||||
ALTER TABLE `school_rosters`
|
||||
DROP INDEX `idx_school_national_id`,
|
||||
DROP INDEX `idx_roster_national_id`,
|
||||
MODIFY `national_id` TEXT NOT NULL,
|
||||
ADD COLUMN `national_id_hash` CHAR(64) NULL AFTER `national_id`,
|
||||
ADD INDEX `idx_roster_national_id_hash` (`national_id_hash`);
|
||||
|
||||
-- Backfill national_id_hash from the application before making these columns
|
||||
-- NOT NULL and UNIQUE. The encryption key must remain the production key.
|
||||
-- The canonical schema already contains national_id_hash. Existing installations
|
||||
-- therefore only need the additive staff/link tables below; no request-time or
|
||||
-- repeated ALTER is performed here.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `staff_accounts` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
||||
Reference in New Issue
Block a user