|
| 1 | +-- Migration: Create flashcards tables |
| 2 | +-- Created: 2024-02-11 |
| 3 | + |
| 4 | +-- Flashcards table: stores AWS concept flashcards |
| 5 | +CREATE TABLE IF NOT EXISTS flashcards ( |
| 6 | + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 7 | + concept_key TEXT NOT NULL UNIQUE, |
| 8 | + front TEXT NOT NULL, |
| 9 | + back TEXT NOT NULL, |
| 10 | + category TEXT NOT NULL, |
| 11 | + difficulty INTEGER DEFAULT 1, |
| 12 | + created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP |
| 13 | +); |
| 14 | + |
| 15 | +-- Index for concept key lookups |
| 16 | +CREATE INDEX IF NOT EXISTS idx_flashcards_concept_key ON flashcards(concept_key); |
| 17 | +CREATE INDEX IF NOT EXISTS idx_flashcards_category ON flashcards(category); |
| 18 | + |
| 19 | +-- Flashcard progress table: tracks user learning progress |
| 20 | +CREATE TABLE IF NOT EXISTS flashcard_progress ( |
| 21 | + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 22 | + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 23 | + flashcard_id UUID NOT NULL REFERENCES flashcards(id) ON DELETE CASCADE, |
| 24 | + known BOOLEAN DEFAULT FALSE, |
| 25 | + review_count INTEGER DEFAULT 0, |
| 26 | + created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, |
| 27 | + last_reviewed_at TIMESTAMPTZ, |
| 28 | + UNIQUE(user_id, flashcard_id) |
| 29 | +); |
| 30 | + |
| 31 | +-- Indexes for performance |
| 32 | +CREATE INDEX IF NOT EXISTS idx_flashcard_progress_user_id ON flashcard_progress(user_id); |
| 33 | +CREATE INDEX IF NOT EXISTS idx_flashcard_progress_flashcard_id ON flashcard_progress(flashcard_id); |
0 commit comments