Files
clientflow_backend/migrations/009_reconciliation_candidate_lookup_indexes.sql

22 lines
956 B
SQL

-- Structured lookup paths used by opportunity-detail reconciliation candidates.
-- Existing opportunity, NIF and source/external indexes are intentionally reused.
CREATE INDEX IF NOT EXISTS idx_reconciliation_customer_id
ON reconciliation_items(customer_id)
WHERE customer_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_reconciliation_customer_email_lower
ON reconciliation_items(lower(customer_email))
WHERE customer_email IS NOT NULL AND customer_email <> '';
CREATE INDEX IF NOT EXISTS idx_reconciliation_customer_name_lower
ON reconciliation_items(lower(customer_name))
WHERE customer_name IS NOT NULL AND customer_name <> '';
CREATE INDEX IF NOT EXISTS idx_commercial_documents_opportunity_number
ON commercial_documents(opportunity_id, document_number)
WHERE document_number IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_commercial_documents_opportunity_external
ON commercial_documents(opportunity_id, external_id)
WHERE external_id IS NOT NULL;