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,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,