ALTER TABLE pages
  ADD COLUMN IF NOT EXISTS render_mode TEXT NOT NULL DEFAULT 'markdown';

DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'pages_render_mode_check'
  ) THEN
    ALTER TABLE pages
      ADD CONSTRAINT pages_render_mode_check CHECK (render_mode IN ('markdown', 'html_document'));
  END IF;
END $$;
