RezinaLMS-BackEnd/db/migrations/000113_generic_assessment_levels.up.sql

43 lines
2.3 KiB
SQL

-- Replace CEFR defaults with curriculum-defined remediation bands while retaining
-- existing assessment data and allowing longer administrator-defined labels.
ALTER TABLE initial_assessment_level_thresholds ALTER COLUMN level TYPE VARCHAR(64);
UPDATE initial_assessment_level_thresholds
SET level = CASE UPPER(TRIM(level))
WHEN 'A1' THEN 'FOUNDATION'
WHEN 'A2' THEN 'DEVELOPING'
WHEN 'B1' THEN 'SECURE'
WHEN 'B2' THEN 'EXTENSION'
WHEN 'C1' THEN 'ADVANCED'
WHEN 'C2' THEN 'MASTERY'
ELSE UPPER(TRIM(level)) END;
ALTER TABLE user_initial_assessment_progress ALTER COLUMN next_level TYPE VARCHAR(64);
ALTER TABLE user_initial_assessment_progress ALTER COLUMN highest_passed_level TYPE VARCHAR(64);
ALTER TABLE user_initial_assessment_progress DROP CONSTRAINT IF EXISTS user_initial_assessment_progress_next_level_check;
ALTER TABLE user_initial_assessment_progress DROP CONSTRAINT IF EXISTS user_initial_assessment_progress_highest_passed_check;
UPDATE user_initial_assessment_progress
SET next_level = CASE UPPER(TRIM(next_level))
WHEN 'A1' THEN 'FOUNDATION' WHEN 'A2' THEN 'DEVELOPING' WHEN 'B1' THEN 'SECURE'
WHEN 'B2' THEN 'EXTENSION' WHEN 'C1' THEN 'ADVANCED' WHEN 'C2' THEN 'MASTERY'
ELSE UPPER(TRIM(next_level)) END,
highest_passed_level = CASE UPPER(TRIM(highest_passed_level))
WHEN 'A1' THEN 'FOUNDATION' WHEN 'A2' THEN 'DEVELOPING' WHEN 'B1' THEN 'SECURE'
WHEN 'B2' THEN 'EXTENSION' WHEN 'C1' THEN 'ADVANCED' WHEN 'C2' THEN 'MASTERY'
ELSE UPPER(TRIM(highest_passed_level)) END;
UPDATE question_sets
SET description = CASE UPPER(TRIM(description))
WHEN 'A1' THEN 'FOUNDATION' WHEN 'A2' THEN 'DEVELOPING' WHEN 'B1' THEN 'SECURE'
WHEN 'B2' THEN 'EXTENSION' WHEN 'C1' THEN 'ADVANCED' WHEN 'C2' THEN 'MASTERY'
ELSE description END,
updated_at = NOW()
WHERE set_type = 'INITIAL_ASSESSMENT'
AND UPPER(TRIM(description)) IN ('A1', 'A2', 'B1', 'B2', 'C1', 'C2');
DROP INDEX IF EXISTS idx_initial_assessment_one_published_per_level;
CREATE UNIQUE INDEX idx_initial_assessment_one_published_per_level
ON question_sets ((UPPER(TRIM(description))), (COALESCE(UPPER(TRIM(owner_type)), 'STANDALONE')), (COALESCE(owner_id, 0)))
WHERE set_type = 'INITIAL_ASSESSMENT'
AND UPPER(TRIM(status)) = 'PUBLISHED'
AND NULLIF(TRIM(description), '') IS NOT NULL;