# Drafts Any record the admin edits (events, people, organizations, blog posts, the front page, the site pages, Navigation, Site settings...) can be saved as a draft instead of going live (migration 077). One draft per record; anyone who can edit the record can save, preview, publish or discard it. ## In the editor - **Save draft** keeps the form as the record's draft. It's checked the way a save is (same field errors), but nothing on the site changes. - **Preview** saves the draft and opens the record's page in a new tab showing it, with an amber bar ("Previewing a draft"). Only a signed-in admin account (viewer and up) sees the draft; anyone else opening that address sees the live page. Stop previewing in the bar returns the tab to the live site. - **Publish** (the Save button, while there's a draft) saves it for real and drops the draft. - **Discard draft** throws it away; the live version is untouched. Opening a record that has a draft opens the draft, with a note saying who saved it and when. If the live record was saved after the draft was started, the note says so: publishing replaces those changes. Lists mark records with a draft. Records not yet created have no drafts: Create is the only save (leave them unpublished until they're ready). ## How it works `server/src/drafts.js`. A draft is the editor's whole form, as a save would send it. Saving one applies it inside a transaction that is always rolled back (`rolledBackSync` in `server/src/db.js`), so it's validated without being written. A preview is a public API read sent with `X-Draft-Preview: /` (`src/lib/api.ts` adds it in a tab opened with `?preview=`): the server opens a second connection to the database, applies the draft in a transaction there, answers the read from it, and rolls back. WAL keeps those writes unseen by every other request. Public reads carry `Vary: X-Draft-Preview`, so a browser never mixes a cached live answer with a preview. `tx()` nests as a savepoint, which is what lets a save run inside the rolled-back transaction. Where each entity's page is: `PREVIEW_PATHS` in `src/lib/adminSchema.ts` (an entity without one has drafts but no Preview button).