-- ClientFlow v4.2 migration 005: operation dashboard helper indexes.
CREATE INDEX IF NOT EXISTS idx_opportunities_status_updated
ON opportunities(status, updated_at DESC);

CREATE INDEX IF NOT EXISTS idx_tasks_status_created
ON tasks(status, created_at DESC);

CREATE INDEX IF NOT EXISTS idx_commercial_documents_kind_created
ON commercial_documents(document_kind, created_at DESC);

CREATE INDEX IF NOT EXISTS idx_commercial_documents_status_created
ON commercial_documents(status, created_at DESC);

CREATE INDEX IF NOT EXISTS idx_shipments_status_created
ON shipments(status, created_at DESC);

CREATE INDEX IF NOT EXISTS idx_products_active_jasmin_missing
ON products(active, jasmin_sales_item)
WHERE active = TRUE;
