godcrm/scripts/historical-chat-parent-index.sql
2026-10-29 07:39:04 +03:00

5 lines
344 B
SQL

-- Authorized migration operator only; outside a transaction (CONCURRENTLY).
-- Required for bounded historical-chat rollback: the self-referencing FK
-- otherwise scans messages once for every deleted message.
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_messages_historical_parent
ON public.messages (parent_id) WHERE parent_id IS NOT NULL;