Make legacy migrations safe on canonical schema

This commit is contained in:
Hamza-Ayed
2026-09-09 17:07:17 +03:00
parent f9851e3b4c
commit 313e994025
2 changed files with 3 additions and 25 deletions
@@ -1,13 +1,6 @@
-- Consolidates additive schema previously created lazily by request handlers. -- Consolidates additive schema previously created lazily by request handlers.
-- Run once on staging/production before disabling runtime DDL. -- 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` ( CREATE TABLE IF NOT EXISTS `teacher_reviews` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`teacher_id` BIGINT UNSIGNED NOT NULL, `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_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 CONSTRAINT `fk_tr_student` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@@ -1,20 +1,6 @@
ALTER TABLE `students` -- The canonical schema already contains national_id_hash. Existing installations
DROP INDEX `national_id`, -- therefore only need the additive staff/link tables below; no request-time or
DROP INDEX `idx_students_national_id`, -- repeated ALTER is performed here.
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.
CREATE TABLE IF NOT EXISTS `staff_accounts` ( CREATE TABLE IF NOT EXISTS `staff_accounts` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,