-- Migration: Add indexes for director proposals and character queries -- Created: 2026-01-12 -- Index für schnelle Suche nach NPCs in einer Region (mit Altersbeschränkung) CREATE INDEX IF NOT EXISTS idx_character_region_user_created ON falukant_data.character (region_id, user_id, created_at) WHERE user_id IS NULL; -- Index für schnelle Suche nach NPCs ohne Altersbeschränkung CREATE INDEX IF NOT EXISTS idx_character_region_user ON falukant_data.character (region_id, user_id) WHERE user_id IS NULL; -- Index für Character-Suche nach user_id (wichtig für getFamily, getDirectorForBranch) CREATE INDEX IF NOT EXISTS idx_character_user_id ON falukant_data.character (user_id); -- Index für Director-Proposals CREATE INDEX IF NOT EXISTS idx_director_proposal_employer_character ON falukant_data.director_proposal (employer_user_id, director_character_id); -- Index für aktive Direktoren CREATE INDEX IF NOT EXISTS idx_director_character_id ON falukant_data.director (director_character_id); -- Index für Director-Suche nach employer_user_id CREATE INDEX IF NOT EXISTS idx_director_employer_user_id ON falukant_data.director (employer_user_id); -- Index für Knowledge-Berechnung CREATE INDEX IF NOT EXISTS idx_knowledge_character_id ON falukant_data.knowledge (character_id); -- Index für Relationships (getFamily) CREATE INDEX IF NOT EXISTS idx_relationship_character1_id ON falukant_data.relationship (character1_id); -- Index für ChildRelations (getFamily) CREATE INDEX IF NOT EXISTS idx_child_relation_father_id ON falukant_data.child_relation (father_id); CREATE INDEX IF NOT EXISTS idx_child_relation_mother_id ON falukant_data.child_relation (mother_id);