-- Audit-final v2 follow-up: cover the FK columns Postgres doesn't auto-index.
-- Without these, deleting a parent row (or RESTRICT-checking on update) walks
-- the child table fully. CREATE INDEX IF NOT EXISTS keeps the migration safe
-- to re-run.

-- berth_reservations  (idx_br_interest is taken by berth_recommendations)
CREATE INDEX IF NOT EXISTS idx_brr_interest
  ON berth_reservations(interest_id);
CREATE INDEX IF NOT EXISTS idx_brr_contract_file
  ON berth_reservations(contract_file_id);

-- documents (file FKs)
CREATE INDEX IF NOT EXISTS idx_docs_file_id
  ON documents(file_id);
CREATE INDEX IF NOT EXISTS idx_docs_signed_file_id
  ON documents(signed_file_id);

-- document_events
CREATE INDEX IF NOT EXISTS idx_de_signer
  ON document_events(signer_id);

-- document_templates
CREATE INDEX IF NOT EXISTS idx_dt_source_file
  ON document_templates(source_file_id);

-- form_submissions
CREATE INDEX IF NOT EXISTS idx_fs_template
  ON form_submissions(form_template_id);
CREATE INDEX IF NOT EXISTS idx_fs_client
  ON form_submissions(client_id);

-- document_sends
CREATE INDEX IF NOT EXISTS idx_ds_brochure
  ON document_sends(brochure_id);
CREATE INDEX IF NOT EXISTS idx_ds_brochure_version
  ON document_sends(brochure_version_id);
CREATE INDEX IF NOT EXISTS idx_ds_sent_by
  ON document_sends(sent_by_user_id);
