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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user