ALTER TABLE documents
  ADD COLUMN IF NOT EXISTS detected_at TIMESTAMPTZ;

UPDATE documents
SET detected_at = COALESCE(detected_at, ingested_at, NOW())
WHERE detected_at IS NULL;

ALTER TABLE documents
  ALTER COLUMN detected_at SET DEFAULT NOW();

