-- GraphRAG plugin initial migration: creates entity_relationships table CREATE TABLE IF NOT EXISTS entity_relationships ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), tenant_id UUID NOT NULL, source_type VARCHAR(50) NOT NULL, source_id UUID NOT NULL, target_type VARCHAR(50) NOT NULL, target_id UUID NOT NULL, relationship_type VARCHAR(50) NOT NULL, metadata JSONB DEFAULT '{}'::jsonb, owner_id UUID REFERENCES users(id) ON DELETE SET NULL, deleted_at TIMESTAMPTZ, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), updated_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS ix_entity_relationships_source ON entity_relationships(tenant_id, source_type, source_id); CREATE INDEX IF NOT EXISTS ix_entity_relationships_target ON entity_relationships(tenant_id, target_type, target_id); CREATE INDEX IF NOT EXISTS ix_entity_relationships_type ON entity_relationships(tenant_id, relationship_type); CREATE INDEX IF NOT EXISTS ix_entity_relationships_source_target ON entity_relationships(tenant_id, source_type, source_id, target_type, target_id); CREATE INDEX IF NOT EXISTS ix_entity_relationships_owner ON entity_relationships(owner_id);