-- The rewrite pass: an author re-authors existing chapter prose in -- their own voice (canon preserved, prose reworked). body_md gets -- overwritten with the rewritten version; body_md_original keeps -- the pre-rewrite prose so the original is never lost. Populated -- only on the FIRST rewrite of a chapter (if NULL) — subsequent -- rewrites leave the original alone. ALTER TABLE chapters ADD COLUMN IF NOT EXISTS body_md_original text; -- Allow 'rewrite' as a generation_runs.kind. ALTER TABLE generation_runs DROP CONSTRAINT generation_runs_kind_check; ALTER TABLE generation_runs ADD CONSTRAINT generation_runs_kind_check CHECK (kind = ANY (ARRAY['gen', 'cleanup', 'audit', 'summary', 'embed', 'narrate_prep', 'rewrite']));