Module 07 · Lesson 7.5
Releasing and Rolling Back
On this page
- What you will learn
- Environments and the release checklist
- Migrations before code: expand, then contract
- A smoke test after every release
- Rolling back, and rehearsing it
- Step-by-step workflow
- Working with an assistant on releases
- Conclusion and your next step
- Reusable prompt
- Expected output
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
Before every flight, pilots with thousands of hours still read a checklist aloud. They do it because the cost of forgetting one item is high, and because memory is least reliable when people are rushed. A release is the same. The moment your system reaches real patients is the wrong moment to improvise.
In this lesson you prepare the first release of the Tidewell booking system. You describe the environments, write a release checklist and learn how to change the database without breaking the version that is already running. You also write a small smoke test, and plan how to go back if the release goes wrong. Then you rehearse that way back before you need it.
What you will learn
- Describe local, staging and production environments, and the settings that differ between them.
- Prepare a release checklist covering settings, migrations before code, a version tag, a smoke test and a rollback plan.
- Write and run a smoke test with an injectable fetch, and read its results.
- Plan a rollback, and explain why database changes are rolled forward with a new migration and not edited or undone.
Before you start
- Completed Continuous Integration Pipelines, or have a project whose checks run automatically.
- Access to any capable AI assistant.
- Optional: Node.js and the project from earlier lessons, if you want to run the examples.
Environments and the release checklist
A release is the moment a new version of the system goes to the people who use it. Between your laptop and that moment sit one or more environments: separate copies of the running system, each with its own settings and data.
- Local
- Your own computer, where you build and try things. It uses synthetic data and a
.env.localfile. - Staging
- A copy of the live system for rehearsal. You release here first, to see what happens before real people do.
- Production
- The real system that patients and staff use, with real data. Only a few named people may change it.
- Environment variable
- A setting given to the program from outside, such as the database address. The name is the same everywhere, and the value differs per environment.
| Environment | Who uses it | Data | Settings |
|---|---|---|---|
| Local | The developer | Synthetic | Values in .env.local, which is not committed. |
| Staging | The team, for rehearsals | Synthetic. Never a copy of patient data. | Its own DATABASE_URL, and its own AUTH_SECRET. Email in a sandbox or test mode. |
| Production | Patients and staff | Real, under the clinic's data-protection duties (CON-01) | Its own values, held in the host's protected settings. |
Tidewell needs four settings, checked at start-up by config.ts from Module 3: DATABASE_URL, APP_BASE_URL, EMAIL_API_KEY and AUTH_SECRET (the last arrived with sign-in in Module 6). Every environment must have its own random AUTH_SECRET. A secret shared between staging and production means a leak in staging is a leak in production.
The release checklist turns 'did we forget anything?' into a list. Keep it in the repository, so it is reviewed and improved like code. Each item is a yes or no, and some name the person who answers.
# Release checklist
Release: v1.0.0 Date: ____ Done by: ____ (role)
## Before
- [ ] All checks passed on main (lint, format, types, tests).
- [ ] The release notes are written (CHANGELOG.md).
- [ ] Settings exist in this environment: DATABASE_URL, APP_BASE_URL, EMAIL_API_KEY, AUTH_SECRET.
- [ ] A backup of the database exists, and its time is noted.
- [ ] Every new migration is additive (the previous version still works with it).
- [ ] The rollback plan is read, and the previous version's tag is written down.
## Release
- [ ] Migrations applied BEFORE the new code (npm run migrate).
- [ ] New code deployed.
- [ ] Version tag created and pushed.
## After
- [ ] Smoke test passed against this environment (npm run smoke).
- [ ] One real journey tried by hand (sign in, view free slots).
- [ ] Front-desk staff told, by role, that the release is done.
## If something is wrong
- [ ] Roll back to the previous tag. Run the smoke test again. Record what happened.A starting checklist. Adapt it to your host and your team.
A version tag is a named marker in Git, such as v1.0.0, that points to the exact code you released. Many projects follow Semantic Versioning (opens in a new tab): three numbers, where a new first number means a change that may break users, a new second number adds features and a new third number fixes bugs. A changelog lists the changes in each version in plain words for people. Keep a Changelog (opens in a new tab) suggests a simple layout.
git tag -a v1.0.0 -m "First release: booking, cancelling and sign-in"
git push origin v1.0.0Create the tag on the exact commit you are releasing, then share it.
Migrations before code: expand, then contract
Releasing code is simple. Releasing code that needs a new database shape is not, because the database and the code cannot change at exactly the same moment. For a short while one of them is ahead of the other. Think of changing the plug on a lamp and the socket in the wall. You cannot swap both in the same second, so you fit a socket that takes both plugs first.
The safe order has two rules. First, apply database migrations before the new code. Second, make every migration additive, so the version that is still running, and the previous version you may roll back to, keep working with it. Martin Fowler calls the full pattern Parallel Change (opens in a new tab), and it is often described as expand, then contract.
- Expand: add the new thing next to the old one. Both versions of the code work.
- Migrate: release code that uses the new thing, and keep the old one in place.
- Contract: in a later release, once nothing uses the old thing, remove it.
| Change | Safe in one release? | Safe way |
|---|---|---|
| Add an optional column | Yes | Add it. Old code ignores it. |
| Add a required column | No | Add it as optional, fill it in, release code that writes it, then make it required later. |
| Rename a column | No | Add the new column, write both, move the reads, and drop the old column in a later release. |
| Drop a column or table | Only when nothing uses it | Remove all uses first, release, and drop in a later release. |
| Edit a migration that was already applied | Never | Add a new migration. Applied ones are history. |
Here is an expand migration for a new optional field, the reason a patient gave when cancelling. The number 007 follows the migrations from Module 6. In the kit used for these tests, only the Module 4 migrations exist, but the file still shows the idea.
-- Expand: add something new and optional. Nothing the running version uses is touched.
ALTER TABLE bookings ADD COLUMN cancel_reason text;Now prove it. The script below plays the 'previous version', which is the booking service you already have, and asks one question: after this migration, can the previous version still book and cancel? It tries a safe migration (the file above) and an unsafe one (a rename in one step).
// Can the PREVIOUS version of the code still run after a migration? If not, rollback is not safe.
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import type { PGlite } from "@electric-sql/pglite";
import { cancelBooking, createBooking } from "./service";
import { freshDatabase, NOW } from "./seed";
// "The previous version" is the service code you already have. It books, then cancels.
async function previousVersionStillWorks(db: PGlite): Promise<string> {
try {
const ctx = { db, patientId: 1, now: NOW };
const booking = await createBooking(ctx, 4);
const result = await cancelBooking(ctx, booking.bookingId);
return `yes (booked, then ${result.status})`;
} catch (error) {
return `NO: ${error instanceof Error ? error.message : String(error)}`;
}
}
const expand = await readFile(join(import.meta.dirname, "release-migrations", "007_add_cancel_reason.sql"), "utf8");
const breaking = "ALTER TABLE bookings RENAME COLUMN cancelled_at TO canceled_at;";
const a = await freshDatabase();
await a.exec(expand);
console.log("After 007_add_cancel_reason.sql (adds a column):");
console.log(" previous version still works?", await previousVersionStillWorks(a));
const b = await freshDatabase();
await b.exec(breaking);
console.log("After renaming bookings.cancelled_at in one step:");
console.log(" previous version still works?", await previousVersionStillWorks(b));After 007_add_cancel_reason.sql (adds a column):
previous version still works? yes (booked, then cancelled)
After renaming bookings.cancelled_at in one step:
previous version still works? NO: column "cancelled_at" of relation "bookings" does not existThe added column is harmless. The old code names the columns it uses, so a new column changes nothing for it. The rename breaks the old code at once, with a message from PostgreSQL itself. If you had released that rename and found a problem, you could not roll back to the previous version, because it cannot run on the new database. This check, run in staging, tells you whether your rollback plan is real.
A smoke test after every release
The name comes from electronics: switch the new circuit on and see if smoke comes out. A smoke test is a handful of quick checks that the main parts of a released system are alive. It is not a test suite. It runs against the real environment right after a release, and it answers one question: 'Is it obviously broken?'
Tidewell's smoke test makes four read-only requests, so it creates no data and is safe in production. It checks that the home page and the sign-in page load, that the list of clinicians is a JSON array, and that asking for bookings without signing in is refused with the sign-in-required problem. That last check proves the protection from Module 6 is switched on in this environment.
// A few quick, read-only checks that a release is alive. Not a test suite.
export type FetchLike = (url: string, init?: { signal?: AbortSignal }) => Promise<Response>;
export interface SmokeResult {
name: string;
ok: boolean;
detail: string;
}
interface SmokeCheck {
name: string;
path: string;
// Returns null when the answer is right, or a short description of what is wrong.
verify: (response: Response) => Promise<string | null>;
}
const expectStatus = (expected: number) => async (response: Response) =>
response.status === expected ? null : `expected ${expected}, got ${response.status}`;
const CHECKS: SmokeCheck[] = [
{ name: "home page loads", path: "/", verify: expectStatus(200) },
{
name: "clinicians list is a JSON array",
path: "/api/clinicians",
verify: async (response) => {
const wrongStatus = await expectStatus(200)(response);
if (wrongStatus) return wrongStatus;
return Array.isArray(await response.json()) ? null : "expected a JSON array";
},
},
{ name: "sign-in page loads", path: "/sign-in", verify: expectStatus(200) },
{
name: "bookings need sign-in",
path: "/api/bookings",
verify: async (response) => {
const wrongStatus = await expectStatus(401)(response);
if (wrongStatus) return wrongStatus;
const problem = (await response.json()) as { type?: string };
return problem.type?.endsWith("/sign-in-required") ? null : "expected the sign-in-required problem";
},
},
];export async function runSmokeTest(baseUrl: string, fetchFn: FetchLike = fetch): Promise<SmokeResult[]> {
const results: SmokeResult[] = [];
for (const { name, path, verify } of CHECKS) {
try {
const response = await fetchFn(new URL(path, baseUrl).toString(), { signal: AbortSignal.timeout(5000) });
const problem = await verify(response);
results.push({ name, ok: problem === null, detail: problem ?? "ok" });
} catch (error) {
// A timeout or a refused connection is a failed check, not a crash.
results.push({ name, ok: false, detail: `no answer (${error instanceof Error ? error.name : "error"})` });
}
}
return results;
}
export function formatResults(results: SmokeResult[]): string {
return results.map((r) => ` ${r.ok ? "PASS" : "FAIL"} ${r.name}: ${r.detail}`).join("\n");
}What each part does
- Each check is a name, a path and a
verifyfunction.verifyreturnsnullwhen the answer is right and a short reason when it is wrong. runSmokeTest(baseUrl, fetchFn)takesfetchas a parameter, as the API client did in Module 5. In production it uses the real one. In tests, you pass a fake website.AbortSignal.timeout(5000)gives each request five seconds. A site that never answers fails the check and does not hang the script.- A thrown error, such as a refused connection, is caught and reported as 'no answer'. A smoke test must report a broken site, not crash because of it.
- The script never prints cookies, headers or response bodies, so a failing run cannot leak anything.
To try it without a real site, the demo below uses a fake fetch for a healthy release and a broken one, and then runs the real fetch against a tiny stand-in server on your own computer.
import { createServer } from "node:http";
import type { AddressInfo } from "node:net";
import { formatResults, runSmokeTest, type FetchLike } from "./smoke-test";
const signInRequired = () =>
Response.json(
{ type: "https://tidewell.example/problems/sign-in-required", title: "Sign-in required", status: 401, detail: "Please sign in." },
{ status: 401, headers: { "Content-Type": "application/problem+json" } },
);
// A pretend website. Each route can be replaced to simulate a broken release.
function fakeSite(overrides: Record<string, () => Response> = {}): FetchLike {
const routes: Record<string, () => Response> = {
"/": () => new Response("<h1>Tidewell Physiotherapy</h1>"),
"/api/clinicians": () => Response.json([{ id: 1, displayName: "Clinician A" }]),
"/sign-in": () => new Response("<h1>Sign in</h1>"),
"/api/bookings": signInRequired,
...overrides,
};
return async (url) => (routes[new URL(url).pathname] ?? (() => new Response("Not found", { status: 404 })))();
}
console.log("1. A healthy release (fake fetch)");
console.log(formatResults(await runSmokeTest("https://staging.tidewell.example", fakeSite())));
console.log("\n2. A broken release (fake fetch)");
const broken = fakeSite({
"/api/clinicians": () => new Response("Internal Server Error", { status: 500 }),
"/sign-in": () => {
throw new DOMException("The operation timed out.", "TimeoutError");
},
"/api/bookings": () => Response.json([{ bookingId: 1 }]),
});
console.log(formatResults(await runSmokeTest("https://staging.tidewell.example", broken)));console.log("\n3. The real fetch, against a stand-in server on this computer");
const server = createServer(async (request, response) => {
const answer = await fakeSite()(`http://localhost${request.url}`);
response.writeHead(answer.status, { "Content-Type": answer.headers.get("content-type") ?? "text/plain" });
response.end(await answer.text());
});
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const { port } = server.address() as AddressInfo;
console.log(formatResults(await runSmokeTest(`http://127.0.0.1:${port}`)));
server.close();1. A healthy release (fake fetch)
PASS home page loads: ok
PASS clinicians list is a JSON array: ok
PASS sign-in page loads: ok
PASS bookings need sign-in: ok
2. A broken release (fake fetch)
PASS home page loads: ok
FAIL clinicians list is a JSON array: expected 200, got 500
FAIL sign-in page loads: no answer (TimeoutError)
FAIL bookings need sign-in: expected 401, got 200
3. The real fetch, against a stand-in server on this computer
PASS home page loads: ok
PASS clinicians list is a JSON array: ok
PASS sign-in page loads: ok
PASS bookings need sign-in: okIn the broken release, three of the four checks failed, in three different ways: a wrong status, no answer at all and a missing sign-in protection. The last one is the most serious. Bookings were readable without signing in. A smoke test that only checked 'the site is up' would have missed it.
To run it against a real environment, wrap it in a small command that takes the address and sets the exit code, so a script or a person can tell pass from fail.
import { formatResults, runSmokeTest } from "./smoke-test";
const baseUrl = process.argv[2] ?? process.env.APP_BASE_URL;
if (!baseUrl) {
console.error("Usage: npx tsx smoke-cli.ts <base url> (or set APP_BASE_URL)");
process.exit(2);
}
const results = await runSmokeTest(baseUrl);
console.log(formatResults(results));
process.exitCode = results.every((r) => r.ok) ? 0 : 1;In the project this is the smoke script: run npm run smoke -- https://staging.example.com with your own staging address, or set APP_BASE_URL. Type-checked here. It was run without an address, which prints the usage message.
Rolling back, and rehearsing it
A rollback means going back to the previous working version when a release goes wrong. For the code, this is usually simple: deploy the previous version again. Most hosts keep earlier builds, or you can deploy the previous Git tag. The exact buttons depend on your host, so read its documentation and write the steps in your own words in the plan.
The database is different. You do not undo applied migrations by editing them or by running the steps backwards in a hurry. Undoing a change that already holds real data can lose that data. Instead, you roll forward: you write a new migration that fixes the problem. This is why the migrations in a release must be additive. The previous version can run on the new database, and no data has to be thrown away to go back.
| Situation | What to do |
|---|---|
| The smoke test fails right after the release | Roll back at once, run the smoke test again, then investigate. |
| A bug is found some hours later, and the fix is small | Fix forward with a new change through the normal pipeline, if it is faster and safer than a rollback. |
| A bug is found later, and the previous version can still run on the new database | Roll back the code. Plan the fix. |
| Data is wrong or missing | Stop. Do not improvise on production data. Tell the owner and restore from the backup with a person who knows how. Module 8 covers backups and restore tests. |
A rollback plan that has never been tried is a hope. Rehearse it in staging at least once. Release a version, roll it back and run the smoke test again, with a stopwatch and a notebook. You find the missing step, the lost password or the command that does not work while it is cheap to find out.
- Release version A to staging and run the smoke test.
- Release version B, which includes an expand migration, and run the smoke test.
- Roll back to version A and run the smoke test again.
- Run the 'can the previous version still run?' check, such as
rollback-check.ts, for the migrations in B. - Write down the time it took, every step that was unclear and who did what.
Name who decides and who is told, by role. For Tidewell, the developer decides to roll back and the practice manager is told straight away, so front-desk staff know whether to use the old diary. For a gentler tool, read Zero-Downtime Deployments: Feature Flags, Blue-Green, and AI-Generated Rollout Plans. A feature flag lets you switch a new feature off without redeploying anything.
Step-by-step workflow
Step 1: List the environments and their settings
Write down local, staging and production, and the four settings for each. Confirm that staging uses synthetic data only.
What you should see: A table of environments in your operating notes.
Step 2: Check each migration for safety
For every new migration, ask: can the previous version still run with it? If not, split it into expand and contract.
What you should see: Every migration in the release is additive.
Step 3: Write the checklist and the rollback plan
Put docs/release-checklist.md in the repository. Name the previous version's tag, who decides and who is told.
What you should see: A checklist someone else could follow.
Step 4: Release to staging and run the smoke test
Apply migrations first, then deploy the code, then run the smoke test against staging.
What you should see: All smoke checks pass in staging.
Step 5: Rehearse the rollback in staging
Roll back to the previous tag and run the smoke test again. Note the time and any surprise.
What you should see: A rollback that has been tried, with notes.
Step 6: Release to production, tag it and run the smoke test
Follow the checklist. Create the version tag, and run the smoke test against production.
What you should see: A tagged release, and a passing smoke test on production.
- Checks pass
Pipeline is green
- Backup
Time noted
- Migrate
Additive, before the code
- Deploy
New version, tagged
- Smoke test
Pass or roll back
Migrations go before the code. The smoke test decides whether to carry on or go back.
Working with an assistant on releases
| Task | Assistant's part | Your part |
|---|---|---|
| Draft the checklist | Proposes items from your list of settings and migrations. | Cut and add items for your host. Name the people, by role. |
| Review migrations for safety | Classifies each as safe or unsafe for the previous version, and explains. | Confirm with the rollback check. Its classification is a claim until you run it. |
| Write the smoke test | Drafts the checks and the fake fetch. | Make sure it is read-only, that it has timeouts and that it checks the sign-in protection. |
| Draft the rollback plan | Writes steps in general terms. | Fill in your host's real steps from its documentation, then rehearse them. |
| Run release commands | Nothing on production. Never. | Production changes are made by named people who have read the checklist. |
Conclusion and your next step
A good release is boring. Settings are in place in each environment, migrations are additive and go first, the version is tagged and a smoke test says whether the system is alive. The way back is written down and has been tried once. When something goes wrong, you roll the code back and roll the database forward, and you do not make up the plan on the day.
Your next step: write the release checklist and rollback plan for your capstone, release to a staging copy, and rehearse the rollback once with a stopwatch. Then continue to the next module, Documentation and Governance, where you document the system and record how AI assistance was used.
For more on rollouts, read Zero-Downtime Deployments: Feature Flags, Blue-Green, and AI-Generated Rollout Plans, or see the whole path in Testing, CI/CD and Release.
Reusable prompt
Release plan drafter
Asks the assistant for a release checklist, a safety review of each migration, smoke checks and a rollback plan, while marking host-specific steps as ones to confirm.
You are helping me plan a release. You will not run anything. Do not invent commands for a hosting service I have not named.
Fictional clinic: Tidewell Physiotherapy. A Next.js application with PostgreSQL. Environments: local, staging, production. Settings in every environment: DATABASE_URL, APP_BASE_URL, EMAIL_API_KEY, AUTH_SECRET (never print or ask for values).
Release v1.0.0 includes two migrations:
- 007_add_cancel_reason.sql: adds an optional column cancel_reason to bookings.
- 008_rename_status_column.sql: renames bookings.status to bookings.state.
The previous version of the code is tagged v0.9.0 and must keep working if we roll back.
Tasks:
1. For each migration, say whether the previous version can still run after it is applied, and why. For an unsafe one, describe how to split it into expand and contract steps.
2. Write a release checklist: before, release, after, and if something is wrong. Migrations go before the code.
3. Suggest four read-only smoke checks, including one that confirms an unauthenticated request for bookings is refused.
4. Write a rollback plan: who decides and who is told (by role), how to redeploy the previous version in general terms, and what to do about the database. Mark every host-specific step "Confirm in the host's documentation".
5. List what is not covered.Show the reusable template
Replace each {{placeholder}} with your own details.
You are helping me plan a release. You will not run anything. Do not invent commands for a hosting service I have not named.
Context: {{organisation_and_stack}}. Environments: {{environments}}. Settings in every environment: {{setting_names}} (never print or ask for values).
Release {{version}} includes these migrations:
{{migrations}}
The previous version of the code is tagged {{previous_tag}} and must keep working if we roll back.
Tasks:
1. For each migration, say whether the previous version can still run after it is applied, and why. For an unsafe one, describe how to split it into expand and contract steps.
2. Write a release checklist: before, release, after, and if something is wrong. Migrations go before the code.
3. Suggest four read-only smoke checks, including one that confirms an unauthenticated request for protected data is refused.
4. Write a rollback plan: who decides and who is told (by role), how to redeploy the previous version in general terms, and what to do about the database. Mark every host-specific step "Confirm in the host's documentation".
5. List what is not covered.Expected output and limitations
A verdict per migration with the reason, a split plan for any unsafe one, a checklist in four parts, four smoke checks, a rollback plan with roles and host-specific steps marked for confirmation, and a list of gaps.
007_add_cancel_reason.sql: safe. Old code names its columns, so an extra optional column changes nothing.
008_rename_status_column.sql: UNSAFE. v0.9.0 reads bookings.status, which would no longer exist.
Split: (1) expand: add "state", copy values, keep "status". (2) release code that writes both and reads "state". (3) later release: drop "status".
Rollback plan
- Decides: developer. Told at once: practice manager (and, through them, front-desk staff).
- Redeploy v0.9.0. Confirm in the host's documentation how to promote an earlier build.
- Database: do not undo 007 or 008. Roll forward with a new migration if needed.
Not covered: restoring from a backup, and the email sandbox settings.Limitations to keep in mind
- The assistant cannot see your real migrations unless you paste them, and it may misjudge safety. Run the check on the real files.
- Host-specific steps may be invented or out of date. Confirm each one in the host's documentation.
- A plan is not proof. Rehearse the rollback in staging before you rely on it.
Common errors and how to fix them
The new code is deployed before the migration, and the first request fails.
Why it happens: The code expects a column that does not exist yet.
Fix: Apply additive migrations first, then deploy the code. Put that order in the checklist.
A rollback is needed, but the previous version crashes on the new database.
Why it happens: A migration renamed or removed something the previous version uses.
Fix: Use expand and contract, and run a 'previous version still works?' check on every migration in staging.
The smoke test passes, but patients cannot book.
Why it happens: The smoke test only checks that pages load, and no journey was tried by hand.
Fix: Add checks for the protections and key reads, and try one real journey after each release. Add a check for each incident you meet.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
A release plan for Ferngate
Ferngate's parts app is ready for its first release. It has a staging copy and a production site. One migration in the release renames the column qty to quantity on the parts table. Write the release checklist, split the migration safely, choose four smoke checks and write the rollback plan.
You will need
- Settings: DATABASE_URL, APP_BASE_URL and one more of your choosing for a stock-alert service.
- The previous version is tagged v0.3.0.
- Mechanics use one shared tablet, so a broken release stops the whole workshop. The owner is not technical.
- Endpoints: GET /api/parts returns a list of parts, and GET /api/low-stock returns a list of parts below the threshold.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- Would v0.3.0 still run after the rename? What would it ask the database for?
- A smoke check could be 'the parts page loads', 'GET /api/parts is an array', 'GET /api/low-stock is an array' and 'the home page loads'.
Show a model answer
A strong answer notes that the rename is unsafe, because v0.3.0 reads qty, and splits it: release 1 adds quantity (expand), copies the values and releases code that writes both columns and reads quantity; release 2, once the workshop has used it for a while, drops qty (contract). The checklist lists settings per environment, a backup, migrations first, the tag and the smoke test. The rollback plan makes the developer the decider and tells the owner at once. It redeploys v0.3.0, which still works because qty is still there. The database is not changed back. It names the staging rehearsal with timings and the lessons written down. It is also honest that the tablet is a single point of failure, so a rollback must be quick.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. An optional column is ignored by code that does not know it, so the old version keeps working. A rename or a drop breaks the old code at once, which is why they are split into expand and contract steps over several releases.
Show the answer and explanation
Answer: B. Going back to a known-good version stops the harm quickly, and you can investigate calmly. Editing an applied migration is tempting but it changes history and may not match what the database holds. Waiting means patients find the fault before you do.
Show the answer and explanation
Answer: B. Real bookings live in the tables, so running a change backwards can destroy them, and editing an applied file makes the record untrue. File permissions are not the reason, and rolling forward is not always faster. The safer approach is additive changes plus a new migration to fix problems.
Frequently asked questions
What is a smoke test?
A smoke test is a handful of quick checks that run after a release to see whether the main parts of the system are alive. It is not a full test suite. It should be read-only and short, so you can run it against production safely.
What is a rollback in software?
A rollback is returning to the previous working version after a release goes wrong. For code, it usually means deploying the earlier version again. For the database, it is safer to add a new corrective migration than to undo changes.
What is the difference between staging and production?
Production is the real system used by real people with real data. Staging is a copy used to rehearse releases and try changes safely. It should match production as closely as possible but use synthetic data and its own secrets.
Can I undo a database migration?
Some tools offer a down step, but running it on a database that holds real data can destroy that data. The safer habit is to make migrations additive, so the old code keeps working, and to fix problems with a new migration, never by editing one that is already applied.
- Written by
- PromptFable Editorial
- Last updated 19 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- Parallel Change(opens in a new tab)
Martin Fowler · The expand, migrate and contract pattern for changing an interface or a database without breaking users.
- Evolutionary Database Design(opens in a new tab)
Martin Fowler and Pramod Sadalage · How to change a database in small steps alongside the code that uses it.
- Semantic Versioning 2.0.0(opens in a new tab)
semver.org · Official documentation · The convention for version numbers that many projects use when they tag releases.
- Keep a Changelog(opens in a new tab)
Keep a Changelog · A simple, human-friendly layout for release notes.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.