-- Add a per-block MIME type column.
--
-- Phase 7 (uploadBlob + MIME detection). `uploadBlob` records the
-- client's `Content-Type` (or the sniffed fallback) here so that
-- `com.atproto.sync.getBlob` can serve the right `Content-Type`
-- header without sniffing on every read.
--
-- `IF NOT EXISTS` keeps the migration idempotent — re-running it on
-- a database that already has the column is a no-op rather than an
-- error. Existing rows (from before this migration) leave the
-- column NULL; the read path falls back to magic-byte sniffing and
-- then `application/octet-stream`.

ALTER TABLE repo_blocks ADD COLUMN IF NOT EXISTS mime_type TEXT;

-- An index helps the per-CID mime lookup used by the Tauri shortcut
-- `GET /blob/{cid}`, which scans by CID alone (no DID). We index
-- *all* rows on (cid) — the lookup wants the row regardless of
-- whether mime_type is set, and a partial index would silently
-- regress to a seq-scan when a row's mime_type happens to be NULL.
CREATE INDEX IF NOT EXISTS repo_blocks_cid_idx ON repo_blocks (cid);