-- ============================================================ -- Schema: English Learning App (TOEIC Focus) -- Run this FIRST before seed.sql -- ============================================================ -- TOEIC questions (Part 1–7) CREATE TABLE IF NOT EXISTS questions ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), part INT NOT NULL CHECK (part BETWEEN 1 AND 7), type TEXT, content TEXT NOT NULL, options JSONB NOT NULL DEFAULT '[]', -- ["A. ...", "B. ...", "C. ...", "D. ..."] answer TEXT NOT NULL, -- "A" | "B" | "C" | "D" explanation TEXT, audio_url TEXT, -- Part 1–4 (listening) image_url TEXT, -- Part 1 (photos) created_at TIMESTAMPTZ DEFAULT now() ); -- TOEIC vocabulary (6 topics) CREATE TABLE IF NOT EXISTS vocab ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), word TEXT NOT NULL, phonetic TEXT, meaning_vi TEXT NOT NULL, topic TEXT NOT NULL CHECK (topic IN ('Business', 'Office', 'Travel', 'Finance', 'HR', 'Marketing')), example TEXT, created_at TIMESTAMPTZ DEFAULT now() ); -- Indexes for common query patterns CREATE INDEX IF NOT EXISTS idx_questions_part ON questions(part); CREATE INDEX IF NOT EXISTS idx_vocab_topic ON vocab(topic);