-- 0004: index the staging_journal -> posted_entry_id lookup used by the
-- reports API's "who" derivation (server/src/reports.ts), and by
-- rollback_import_batch()'s reverse cursor (db/migrations/0003_import_layer.sql).
-- Added as a new file rather than editing 0003: migrations are forward-only
-- (CLAUDE.md §1) and the dev DB now holds real posted data.

-- Speeds the per-entry "who" lookup (staging provenance) used by reports.
CREATE INDEX staging_journal_by_posted_entry
  ON staging_journal (company_id, posted_entry_id)
  WHERE posted_entry_id IS NOT NULL;
