18 — Rehearse the release: dev → preprod → prod
Commandments V and VI: a Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary → or a Database swap — Replacing the whole production database with a new version, carrying over user accounts and data. The hardest operation in The Craft — it has its own runbook and needs explicit consent. more in the glossary → run for the first time in the Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary → Maintenance window — A short, planned period when users see a “work in progress” page while the database or configuration changes behind it. It guarantees the app never runs, even briefly, on half-changed data. more in the glossary → is tested on your users. Run the exact Runbook — A written step-by-step guide for production operations, with numbered lessons from incidents. The memory of outages can’t live in someone’s head — the next deploy starts by reading the runbook. more in the glossary → once on a faithful copy first.
Three environments, three jobs
| Environment | Job | Data |
|---|---|---|
| dev (your machine) | build, reproduce bugs | seed data, or an anonymised refresh from a prod Backup — A copy of your data saved earlier, which you return to when something goes wrong. It’s the only way to undo a change to data — code comes back from git, data only from a backup. more in the glossary → |
| Preprod (staging) — A faithful copy of production with no real users, where you rehearse a deploy. A migration that fails on preprod is an ordinary Tuesday; in production it’s an incident. more in the glossary → (server clone of prod: same OS, web server, process manager, TLS) | rehearse migrations and the Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary → itself | anonymised prod backup; basic-auth gated, noindex |
| prod | serve users | sacred — touched only on “deploy”, only with steps rehearsed on preprod the same day |
Add preprod when the project reaches the third branching rung or the first risky migration (→ 05).
Rules
- Build preprod from prod the same way every time — scripted: clone with prod’s deploy key; refresh the database from a prod backup; anonymise PII (personal data) — Information that identifies a person: name, email, address, phone number. They need special protection (GDPR) — they mustn’t end up in logs or on test servers. more in the glossary → before it leaves prod (→ 09).
- Environment-specific values are env-overridable, never hard-coded:
SITE_URL, Canonical — A tag that tells search engines which address is “the real one” for a piece of content. It prevents duplicates (e.g. the same product under several addresses) that split your Google ranking. more in the glossary →, Open Graph (OG) — Tags that decide how a link looks when pasted into Facebook, LinkedIn or a messenger (image, title, description). A good link card means more clicks — a bad one can show what you don’t want (e.g. a price). more in the glossary →, Sitemap — A file listing every address of the site, helping search engines find them. New pages reach search engines faster, and language versions get linked together. more in the glossary → point at preprod — otherwise preprod leaks prod URLs or gets indexed (→ 10). - Rehearse the real runbook, not a simplified one: run the migration, time the window, Smoke test — A quick “does it even work” test right after a deploy — checks the most important paths (e.g. login). Catches disasters in 30 seconds before a user sees them. A cheap way to sleep well after a deploy. more in the glossary →, confirm it is forward-only and Idempotency — A property of an operation you can run many times with the same result — no duplication. Key for scripts and events: a re-run doesn’t break data. Like an “ON” switch. more in the glossary → (→ 04).
- Expect the gotchas only a real preprod surfaces: the ACME/Let’s Encrypt
http-01challenge must bypass basic-auth or renewal fails with 401; a private Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary → needs its SSH — An encrypted connection to a server for sending it commands and transferring files. An SSH key is access to production — guard it like your most important password. more in the glossary → remote before the first pull. - Preprod is a rehearsal stage, never a second prod: no live users, a stale DB is fine, and its database is never swapped back into prod (→ 11).
Anti-patterns
- 🚫 A migration whose first run is the prod maintenance window.
- 🚫 Real, non-anonymised user data on preprod — a second copy of your PII liability on a weaker box.
- 🚫 Preprod indexed or emitting prod URLs.
- 🚫 Treating preprod’s data as a source of truth.