refactor: answer_type single TEXT + new 'question' type

- Convert TEXT[] back to TEXT (take first element of existing arrays)
- Valid values: yes_no, text, question, word
- API validation updated for single string

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 16:11:15 +02:00
parent 7c8d5bfaaf
commit b0a67df328
2 changed files with 18 additions and 11 deletions

View File

@@ -319,11 +319,18 @@ async function migrate() {
)
`);
// pairs.answer_type → TEXT[] (multi-select)
// pairs.answer_type → single TEXT (was TEXT[], now back to single value + new 'question' type)
await query(`ALTER TABLE pairs DROP CONSTRAINT IF EXISTS pairs_answer_type_check`).catch(() => {});
await query(`
ALTER TABLE pairs ALTER COLUMN answer_type TYPE TEXT[]
USING ARRAY[answer_type]::TEXT[]
ALTER TABLE pairs ALTER COLUMN answer_type TYPE TEXT
USING (CASE
WHEN answer_type IS NULL OR array_length(answer_type::TEXT[], 1) IS NULL THEN 'text'
ELSE (answer_type::TEXT[])[1]
END)
`).catch(() => {});
await query(`
ALTER TABLE pairs ADD CONSTRAINT pairs_answer_type_check
CHECK (answer_type IN ('yes_no', 'text', 'question', 'word'))
`).catch(() => {});
// statements.answer — boolean nullable (for yes/no correct answer)