diff --git a/db/migrations/000082_fixup_legacy_audio_question_type_definition.down.sql b/db/migrations/000082_fixup_legacy_audio_question_type_definition.down.sql new file mode 100644 index 0000000..104da48 --- /dev/null +++ b/db/migrations/000082_fixup_legacy_audio_question_type_definition.down.sql @@ -0,0 +1 @@ +-- Data fix is not reversed: legacy AUDIO relinks cannot be restored without a backup. diff --git a/db/migrations/000082_fixup_legacy_audio_question_type_definition.up.sql b/db/migrations/000082_fixup_legacy_audio_question_type_definition.up.sql new file mode 100644 index 0000000..840ebc1 --- /dev/null +++ b/db/migrations/000082_fixup_legacy_audio_question_type_definition.up.sql @@ -0,0 +1,46 @@ +-- Legacy AUDIO questions (voice_prompt / sample_answer fields, no dynamic_payload) were linked to +-- unrelated dynamic definitions (e.g. ielts_speaking_cue_card_part1). Ensure the canonical +-- audio_conversation_type definition exists and relink affected rows. + +INSERT INTO question_type_definitions ( + key, + display_name, + description, + stimulus_component_kinds, + response_component_kinds, + stimulus_schema, + response_schema, + is_system, + status +) +VALUES ( + 'audio_conversation_type', + 'Audio Conversation', + 'Listen to a voice prompt and respond with a spoken answer. Maps to legacy AUDIO questions (voice_prompt, sample_answer_voice_prompt, audio_correct_answer_text).', + ARRAY['QUESTION_TEXT', 'AUDIO_PROMPT']::TEXT[], + ARRAY['AUDIO_RESPONSE']::TEXT[], + '[ + {"id": "question_text_1", "kind": "QUESTION_TEXT", "label": "Question text", "required": false}, + {"id": "voice_prompt_1", "kind": "AUDIO_PROMPT", "label": "Voice prompt", "required": true}, + {"id": "sample_answer_voice_prompt_1", "kind": "AUDIO_PROMPT", "label": "Sample answer voice prompt", "required": false} + ]'::jsonb, + '[ + {"id": "audio_response_1", "kind": "AUDIO_RESPONSE", "label": "Learner audio response", "required": true} + ]'::jsonb, + TRUE, + 'ACTIVE' +) +ON CONFLICT (key) DO NOTHING; + +UPDATE questions q +SET + question_type_definition_id = audio_def.id, + updated_at = CURRENT_TIMESTAMP +FROM question_type_definitions audio_def +WHERE audio_def.key = 'audio_conversation_type' + AND q.question_type = 'AUDIO' + AND q.dynamic_payload IS NULL + AND ( + q.question_type_definition_id IS NULL + OR q.question_type_definition_id IS DISTINCT FROM audio_def.id + );