/ratchet-backend:expand-contract-migrationsfrom ratchet-backend
Use when renaming or dropping a column or table, changing a column type, making a column NOT NULL, renaming an API or event field, splitting or merging tables, or changing a config shape that running code reads. Change a shape in separate deploys so old and new code never disagree.
Ships in ratchet-backend. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Read every applicable AGENTS.md first. Repository-local policy overrides these defaults.
These rules apply wherever old code may run, including a rollback that redeploys it. Only a disposable database, such as a test schema or a local reset, may be renamed, dropped, or constrained in one step.
During every deploy and every rollback, old and new code run at the same time against the same data. A change that only works when all code is new breaks in that window. Make each step work with the version before it and the version after it.
In this order. Steps 1, 2, 5, 6, and 7 are each a deploy of their own; the backfill and the check run between deploys:
Never put an expand and the contract of the same thing in one change. The deploy between them is the only time anything can be undone.
Never rename in place: ALTER TABLE ... RENAME COLUMN breaks every running instance that still
uses the old name, the moment it runs. Add the new name, copy, switch readers, drop the old name.
The same holds for a type change (add a column of the new type) and for a table split or merge
(build the new tables, write both, backfill, switch reads).
Example, users.name to users.full_name: deploy 1 adds a nullable full_name; deploy 2 writes
both; run the backfill; deploy 3 reads full_name; deploy 4 stops writing name; deploy 5 drops
it.
Add a constraint in two steps where the database supports it, so it does not lock the table while it scans:
NOT VALID (new writes are checked at once), then VALIDATE it
in a later statement.For table design and locking, see postgres-schema-design.
A change that lets one parent have many rows (a one-to-one relation becoming one-to-many, a unique constraint dropped) leaves every read that assumed one row wrong. Most fail silently, returning an arbitrary row or a duplicate; a scalar subquery fails loudly, with a "more than one row" error, the first time a parent gains a second row. Before the change ships, find and fix each one:
LIMIT 1 with no ORDER BY that picks the right row, and scalar subqueries;findOne, maybeSingle, and rows[0] on a result that may now hold several rows;JOINs that now multiply the parent's rows.Search the query builders and shared fragments as well as the call sites. Decide what "the one"
now means (the primary, the newest) and make each read say so, for example
ORDER BY is_primary DESC, created_at DESC, id DESC LIMIT 1.
The same sequence applies to anything with a consumer you do not deploy together with the producer. Add the new field alongside the old one, change consumers to read either, then stop sending the old field once no consumer needs it. A consumer that rejects unknown fields must be changed before the producer starts sending the new one.
For flags that gate the switch, and for keeping deploying apart from enabling, see feature-rollout.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
18 skills in this plugin
/bounded-iterationUse when writing or reviewing a sweep, scheduled job, reconciler, cleanup, dispatcher, backfill, or export - any loop that reads rows. Covers bounding the rows each run reads, sweeps that re-select their own writes, and effects that repeat on every run./error-handlingUse when writing or reviewing code that throws, catches, or matches an error, turns a failure into a response, or reports errors to a tracker such as Sentry, including a review of a diff that does. Covers one defined list of error codes, matching on type or code instead of message, details as attributes on the error, and reporting only errors someone can act on./npx claudepluginhub jongleberry/ratchet-stack --plugin ratchet-backend