db-migration-safety
Skill5 starsChanged 4 months agoMITView on GitHub
Review or write a database schema migration with production safety as the bar, checking locks, table rewrites, backfills, expand-contract deploy order, index creation, and rollback for Postgres, MySQL, and common ORMs. Use when adding or reviewing a migration, dropping or renaming columns, or adding constraints or indexes to large tables.
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Read the migration and identify every table it touches, then find out (or ask) roughly how large and how hot each one is.
- Distinctive: line 34
No down migration, or a down migration that drops data the up migration created (state whether down is actually safe to run, not just …
- Very specific: line 40
Run the migration against a local or staging copy and read the SQL the tool actually emits (--dry-run, sqlmigrate, db:migrate:status …
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
A migration that is correct on an empty dev database can still take a production table offline. Judge every migration by what it does under load on the largest table it touches: what lock it takes, for how long, and what the old application version does while the new schema is live. When any answer is "depends", assume the worst table and the slowest query.
Step 1: Establish the blast radius
- Read the migration and identify every table it touches, then find out (or ask) roughly how large and how hot each one is. A pattern that is fine on 10k rows is an outage on 100M.
- Identify the engine and version (Postgres, MySQL 8, SQLite, ...) from config; lock behavior differs materially between them, and between versions.
- Identify the deploy model: is the old app version still running while this migration executes (rolling deploy, multiple replicas)? Almost always yes; review under that assumption.
Step 2: Check the dangerous patterns
Flag any of these, with the safe alternative:
Locking and rewrites
- Any statement that rewrites the table or takes an exclusive lock for its duration: changing a column's type, adding a column with a volatile default (pre-Postgres 11),
ALTER TABLEon MySQL withoutALGORITHM=INPLACE/INSTANTsupport. Alternative: add a new column, backfill, swap. CREATE INDEXwithoutCONCURRENTLY(Postgres) on a live table blocks writes for the build.CONCURRENTLYcannot run inside a transaction; the migration tool must support that (most do via a flag ordisable_ddl_transaction!).- Adding a
NOT NULLconstraint or foreign key that validates existing rows scans the table under lock. Alternative: add asNOT VALID/ unvalidated, thenVALIDATE CONSTRAINTseparately.
Deploy-order breaks (expand-contract violations)
- Dropping or renaming a column or table the currently-deployed code still reads or writes. Renames are two deploys minimum: add new + dual-write, migrate readers, then drop the old one in a later release.
- Making a column
NOT NULLwhile the running app still inserts without it. - Enum or check-constraint tightening that existing rows or in-flight writes violate.
Backfills
- Backfilling inside the schema migration itself, in one transaction. A backfill is data movement, not schema: run it separately, in batches (thousands of rows per batch, pausing between), idempotent and resumable, keyed on primary-key ranges rather than OFFSET.
- Backfill and constraint in one step; the constraint comes after the backfill completes and is verified.
Operational
- No down migration, or a down migration that drops data the up migration created (state whether down is actually safe to run, not just present).
- Long statements without a
lock_timeout/statement_timeoutguard (Postgres): a blockedALTERqueues behind a long-running query and then blocks everything behind it. Set a short lock timeout and retry rather than waiting indefinitely. - Mixing schema change and unrelated data change in one migration file; they have different risk profiles and rollback stories.
Step 3: Verify what can be verified
- Run the migration against a local or staging copy and read the SQL the tool actually emits (
--dry-run,sqlmigrate,db:migrate:statusequivalents); ORMs sometimes generate a rewrite where the model diff looked additive. - Confirm the migration is wrapped (or deliberately not wrapped) in a transaction as the engine requires.
- For the reviewed-only case (no database available), say so, and mark which findings are static-analysis-certain versus needing a dry run.
Step 4: Report
Findings ordered by severity: outage risks (locks, rewrites, deploy-order breaks) first, then correctness (rollback, constraint gaps), then hygiene. For each: the statement, what happens on the big table, and the concrete safe sequence, written as actual migration steps in the project's own tool syntax. If the migration is safe as written, say that plainly and note the one or two assumptions the judgment rests on (table size, engine version).
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Hainrixz/claude-db★ 22same name
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.
In this repository89 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- site/llms-full.txtllms.txt
- site/llms.txtllms.txt
- improveSkill
- academic-writingSkill
- benchmark-reportingSkill
- bibtex-managerSkill
- citation-graphSkill
- citation-verifierSkill
- design-science-methodologySkill
- docx-thesisSkill
- experiment-reproducibilitySkill
- latex-toolkitSkill
- literature-searchSkill
- lit-review-synthesisSkill
- paper-readerSkill
- proofread-academicSkill
- research-figuresSkill
- research-methodologySkill
- research-questionSkill
- statistics-advisorSkill
- supervisor-updateSkill
- systematic-reviewSkill
- thesis-proposalSkill
- coolify-image-appSkill
- coolify-vps-baselineSkill
- deploy-verificationSkill
- express-prisma-coolify-imageSkill
- ghcr-coolify-pipelineSkill
- live-domain-cutoverSkill
- nextjs-coolify-imageSkill
- proxy-client-addressSkill
- vps-ops-toolkitSkill
- adr-writingSkill
- openapi-specSkill
- readme-writingSkill
- technical-writingSkill
- adversarial-reviewerSkill
- api-design-reviewSkill
- code-review-responseSkill
- create-agentSkill
- create-commandSkill
- create-hookSkill
- create-skillSkill
- dependency-upgradeSkill
- dockerfile-best-practicesSkill
- error-handling-patternsSkill
- executing-plansSkill
- explain-codebaseSkill
- fix-ciSkill
- github-actions-pipelineSkill
- grill-with-docsSkill
- incident-postmortemSkill
- logging-and-observabilitySkill
- parallel-agentsSkill
- performance-optimizationSkill
- refactoring-recipesSkill
- solid-principlesSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

