# Deploy preflight
<!-- From chapter 9. The deploy is a procedure, not an event: before, during, after. -->

## Before
- [ ] Type-check first.
- [ ] After renaming routes, clear the framework's build cache and check again.
- [ ] The rulebook's automated checks pass as part of the build (cost rules included).
- [ ] The change is verified on a preview deployment built from the same code.
- [ ] Environment variables are set in a way that cannot add a trailing newline (e.g. `printf '%s'`).

## During
- [ ] Deploy from a known commit, on the branch production is configured to serve.
- [ ] Ship small: one change, verified, shipped, recorded. Then the next one.

## After
- [ ] Read the sitemap and request every public page from the live domain. Every route must return 200, not just the home page.
- [ ] Private pages answer the way they should: a redirect to sign-in, not an error and not the page itself.
- [ ] Walk the main user path in a real browser (sign in, do the thing the change was for).
- [ ] Update the changelog and the handoff before calling the deploy done.
- [ ] If a route fails: wait briefly and retry a small, fixed number of times.
- [ ] Still failing: roll back to the last working version, then investigate.
- [ ] Write the failure report: which deployment failed, which is now live, which routes failed, what they returned, how many attempts.
- [ ] Rollback restores code, not data. Changes that touch the database get their recovery planned before the deploy, not improvised after it.
