db-migrate
Skill1 starsChanged 2 months agoApache-2.0View on GitHub
Author or review a Drizzle DB migration for zero-downtime safety — expand/contract phasing, backward-compatibility with the deployed app version, and writing the `-- migration-safe` acknowledgment the check:migrations lint requires. Use when adding/editing files under `packages/db/migrations/` or changing `packages/db/schema.ts`.
We split this skill into the rules it gives an agent
4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Never put expand and contract in the same PR.
- Very specific: line 46
When an expand defers a drop, leave a contract-pending marker on the legacy column/table in packages/db/schema.ts — that is the file you …
- Very specific: line 76
Run bun run check:migrations (base defaults to origin/staging).
- Very specific: line 85
Verify locally: cd packages/db && bun run db:migrate against a dev DB.
“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DB Migrate Skill
You make schema changes that survive a deploy without downtime. The check:migrations lint (scripts/check-migrations-safety.ts) is the deterministic gate; you are the judgment that decides whether a flagged change is actually safe and writes the annotation that satisfies it.
The window (why this matters)
A deploy runs the migration, then rolls out the new app image via blue/green. The two are not atomic and cannot be — during cutover the old task set keeps serving against the already-migrated schema. So:
Every migration must be backward-compatible with the app version that is already deployed.
If a migration drops a column the old code still reads, renames one, or adds a NOT NULL the old inserts don't populate, the old code throws until traffic fully shifts — the downtime we're guarding against. You can't fix this by reordering the pipeline; the only fix is discipline.
Expand / contract
Split every breaking change across two deploys:
- Expand (this PR): additive, backward-compatible schema + code that tolerates both the old and new shape.
- Contract (a later PR, after expand is fully deployed): remove the old thing, now that nothing reads it.
Never put expand and contract in the same PR. If this PR both removes the code that used a column and drops the column, the old code is still live during cutover — split it.
Per-operation playbook
| You want to | Do (deploy 1 = expand) | Do (deploy 2 = contract) |
| Add a required column | ADD COLUMN nullable or DEFAULT; code writes it | backfill, then SET NOT NULL |
| Rename a column/table | add the new name; code dual-writes / reads new-then-old | drop the old name |
| Drop a column/table | stop all reads/writes in code; ship it | DROP (annotate) |
| Change a column type | add a new column of the new type; dual-write | backfill, swap reads, drop old |
| Add FK / CHECK | ADD CONSTRAINT ... NOT VALID | VALIDATE CONSTRAINT separately |
| Index an existing table | COMMIT; breakpoint → SET lock_timeout = 0 → CREATE INDEX CONCURRENTLY IF NOT EXISTS (see packages/db/scripts/migrate.ts) | — |
| Drop an index | COMMIT; breakpoint → DROP INDEX CONCURRENTLY — plain DROP INDEX takes ACCESS EXCLUSIVE on the table | — |
| Backfill data | batched + idempotent UPDATE (keyset/WHERE, bounded) | — |
A CREATE INDEX, ADD COLUMN, or ADD CONSTRAINT against a table created in the same migration is always safe (no rows, no live traffic) — the lint already suppresses those.
Tracking the contract (don't let it rot)
The contract half is deferred to a later deploy — and that is exactly when it gets forgotten, leaving dead columns, orphaned tables, and NOT NULLs that never land. Every deferred contract must become a durable, greppable TODO.
When an expand defers a drop, leave a contract-pending marker on the legacy column/table in packages/db/schema.ts — that is the file you will be editing when you finally do the drop, so the reminder lives where the work happens:
// contract-pending(after #5035 is fully deployed): drop once permission-check.ts stops reading it
workspaceId: text('workspace_id'),Format: contract-pending(<precondition>): <what to drop> — <why it's safe once the precondition holds>. The precondition names the PR/release that removes the last reader and must be fully deployed before the contract ships.
- The TODO list is a grep — always accurate, never drifts:
grep -rn "contract-pending" packages/db apps/sim. Run it when starting migration work to see what is owed. - For anything with a real owner or schedule, also open a tracking issue and put its number in the marker.
- Close the loop in the contract PR: the contract migration's
-- migration-safe:annotation references the expand, and you delete thecontract-pendingmarker in the same PR:-- migration-safe: contract of #5035 — workspace_id readers removed there, deployed 2026-06-10 ALTER TABLE "permission_group" DROP COLUMN "workspace_id"; - An expand merged without a marker for the drop it defers, or a contract merged without removing its marker, is a bug — flag it in review.
The judgment the lint can't do
The lint flags risky shapes; it cannot know whether a given drop is safe right now. For each flagged statement, do the work it can't:
- Is the dependency gone? Grep the app for the table/column: search
apps/simandpackagesfor the column name, the Drizzle field (camelCase), and the table object. If any live read/write remains, it is not safe — fix the code first. - Did the expand already ship? The removal of that read/write must be in a deploy that is already out, not this same PR. If it's in this PR, split: land the code change now, do the destructive migration in a follow-up after it deploys.
- Backfills: confirm the
UPDATE/DELETEis batched (boundedWHERE/keyset, not a single whole-table statement), idempotent (safe to replay — a failed migration re-runs unjournaled files from the top), and safe under concurrent writes from the still-live old app.
Workflow
- Edit
packages/db/schema.ts, thencd packages/db && bunx drizzle-kit generateto produce the SQL. If this is an expand that defers a drop, leave acontract-pendingmarker on the legacy column (see "Tracking the contract"). If this is the contract, delete the marker it resolves. - Hand-edit the generated SQL where the playbook requires it:
CONCURRENTLY+COMMIT;breakpoint for indexes on existing tables,NOT VALIDfor constraints, batching for backfills. - Run
bun run check:migrations(base defaults toorigin/staging).- Hard errors (
add-not-null-no-default,rename,index-not-concurrent,constraint-not-valid, …): rewrite into expand/contract. Do not try to annotate them away — the lint won't accept it. - Annotate tier (
drop-table,drop-column,drop-default,set-not-null,alter-type,drop-index): only after you've confirmed steps 1–3 above, add a comment on the line directly above the statement:
The reason must be specific and name the PR/version that removed the dependency. An empty reason fails the lint.-- migration-safe: `secret` read removed in v0.6.1 (#1234), shipped two deploys ago ALTER TABLE "webhook" DROP COLUMN "secret"; - Warnings (
data-backfill): non-blocking, but confirm the batching/idempotency before merging.
- Hard errors (
- Verify locally:
cd packages/db && bun run db:migrateagainst a dev DB.
Hard rule
Never annotate a destructive statement just to make the lint pass. The annotation is a claim that you verified the old code no longer depends on it. If you can't make that claim truthfully, the change belongs in a later deploy — tell the user to split it.
Other versions18 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- simstudioai/sim★ 30k87% same
Wrote their own version · 17
- lablup/backend.ai★ 675same name
- linuxfoundation/insights★ 283same name
- alexeykrol/claude-code-starter★ 194same name
- suxrobGM/jobpilot★ 104same name
- getsentry/abacus★ 77same name
- lfrodrigues/packt-claude-code-course-auth★ 9same name
- mgiovani/cc-arsenal★ 8same name
- mean-weasel/bullhorn★ 4same name
- pgnzbl-ux/crucible★ 4same name
- vndee/engineering-skills★ 3same name
7 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use deploy, commit and 1 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
VercelSkilldeploy
Deploy applications to Vercel. Use when the user says "deploy", "deploy to Vercel", "push to production", "deploy my app", or "go live".
Also in 4 projects that use this
SentrySkillcommit
Create commit messages following Sentry conventions. Use when committing code changes, writing commit messages, or formatting git history. Follows conventional commits with Sentry-specific issue references.
Also in 3 projects that use this
MicrosoftSkillrelease
Use ONLY when the user explicitly asks to cut/publish a Huabu desktop release or tag a version. Performs an outward action — bumps the version in apps/desktop/package.json, commits + annotated-tags vX.Y.Z, and pushes the branch + tag. That tag push auto-builds the macOS/Windows installers and publishes a GitHub Release. Provides `status`, `bump`, `tag-push`, and a one-command `run` (bump → tag-push).
Also in 3 projects that use this
In this repository54 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/constitution.mdcCursor rule
- .cursor/rules/emcn-components.mdcCursor rule
- .cursor/rules/global.mdcCursor rule
- .cursor/rules/landing-seo-geo.mdcCursor rule
- .cursor/rules/sim-architecture.mdcCursor rule
- .cursor/rules/sim-components.mdcCursor rule
- .cursor/rules/sim-hooks.mdcCursor rule
- .cursor/rules/sim-imports.mdcCursor rule
- .cursor/rules/sim-integrations.mdcCursor rule
- .cursor/rules/sim-queries.mdcCursor rule
- .cursor/rules/sim-sandbox.mdcCursor rule
- .cursor/rules/sim-stores.mdcCursor rule
- .cursor/rules/sim-styling.mdcCursor rule
- .cursor/rules/sim-testing.mdcCursor rule
- .cursor/rules/sim-typescript.mdcCursor rule
- .cursor/rules/sim-ui-copy.mdcCursor rule
- add-block-previewSkill
- add-blockSkill
- add-column-typeSkill
- add-connectorSkill
- add-enrichmentSkill
- add-feature-flagSkill
- add-hosted-keySkill
- add-integrationSkill
- add-managed-cliSkill
- add-modelSkill
- add-toolsSkill
- add-triggerSkill
- babysitSkill
- cleanupSkill
- councilSkill
- design-taste-frontendSkill
- emcn-design-reviewSkill
- emil-design-engSkill
- make-interfaces-feel-betterSkill
- memory-load-checkSkill
- migrate-application-operationSkill
- react-query-best-practicesSkill
- shipSkill
- tool-registry-boundarySkill
- v2-api-conventionsSkill
- validate-connectorSkill
- validate-integrationSkill
- validate-modelSkill
- validate-triggerSkill
- you-might-not-need-a-callbackSkill
- you-might-not-need-a-commentSkill
- you-might-not-need-a-memoSkill
- you-might-not-need-an-effectSkill
- you-might-not-need-stateSkill
- you-might-not-need-url-stateSkill
- add-settings-pageSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

