package database // ParentMigrations creates the four parent-side tables for Phase 9c: // // parent_account — one row per invited parent (email, language) // parent_child — kids linked to a parent and a tt_class // parent_magic_link — one-shot invite tokens, hashed // parent_session — active browser sessions after redeeming a link // // The teacher owns the invite (created_by_user_id on account); parent sees // only data scoped to their own children's class via tt_class.id. func ParentMigrations() []string { return []string{ `CREATE TABLE IF NOT EXISTS parent_account ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), created_by_user_id UUID NOT NULL, email VARCHAR(255) NOT NULL, preferred_language VARCHAR(8) DEFAULT 'de', created_at TIMESTAMPTZ DEFAULT NOW(), UNIQUE(created_by_user_id, email) )`, `CREATE TABLE IF NOT EXISTS parent_child ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), parent_id UUID NOT NULL REFERENCES parent_account(id) ON DELETE CASCADE, tt_class_id UUID NOT NULL REFERENCES tt_class(id) ON DELETE CASCADE, first_name VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW() )`, `CREATE TABLE IF NOT EXISTS parent_magic_link ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), parent_id UUID NOT NULL REFERENCES parent_account(id) ON DELETE CASCADE, token_hash VARCHAR(64) NOT NULL UNIQUE, expires_at TIMESTAMPTZ NOT NULL, used_at TIMESTAMPTZ, created_at TIMESTAMPTZ DEFAULT NOW() )`, `CREATE TABLE IF NOT EXISTS parent_session ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), parent_id UUID NOT NULL REFERENCES parent_account(id) ON DELETE CASCADE, token_hash VARCHAR(64) NOT NULL UNIQUE, expires_at TIMESTAMPTZ NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW() )`, `CREATE INDEX IF NOT EXISTS idx_parent_account_owner ON parent_account(created_by_user_id)`, `CREATE INDEX IF NOT EXISTS idx_parent_child_parent ON parent_child(parent_id)`, `CREATE INDEX IF NOT EXISTS idx_parent_child_class ON parent_child(tt_class_id)`, } }