agentleFS
XData-siXData-si/xdata-agenthub/skills/database-migrations/SKILL.md

database-migrations

Skill1 starsChanged 33 days agoMITView on GitHub

Plan and review schema and data migrations that deploy without downtime or data loss, using expand-contract, batching and tested rollback. Use when adding, renaming or removing columns, tables, indexes or constraints, or backfilling data.

71 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use docker-and-compose, add-a-use-case and 10 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.
  • JameMy0001Skill

    docker-and-compose

    Production containerization patterns, multi-stage Dockerfiles, Docker Compose orchestrations, non-root security hardening, and cache optimization.

    Also in 6 projects that use this

  • LeanMeanCleanAppsSkill

    add-a-use-case

    How to add a command or query to the Application layer as a vertical slice (request, handler, validator, tests) using source-generated Mediator. Use when adding a new feature, a new query, or a new write operation.

    Also in 5 projects that use this

  • LeanMeanCleanAppsSkill

    branches-and-pull-requests

    Branch naming (feature/, fix/, chore/), how labels and release notes follow from the branch, the pull request template, and how changes get merged in the template repository. Use when creating a branch, writing a commit or opening a pull request.

    Also in 5 projects that use this

  • +9 more from LeanMeanCleanApps

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 68 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No step breaks the currently deployed application version.

    line 52
  2. Distinctive:

    Never run migrations against production without approval and a fresh backup.

    line 61

“Common” is measured: kept by at least 6 in 10 of the 68 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Zero-Downtime Database Migrations

Goal

Change the schema while old and new application versions run side by side, with a verified way back.

Inputs

  • Migration files and the ORM or migration tool in use.
  • Table sizes and row counts, write rate, replication setup, database engine and version.
  • Deployment model: rolling, blue-green, or a single instance with a restart.

Procedure

  1. Classify each change.
    ChangeRisk
    add nullable column, new tablelow
    add index on a large tablelocks writes unless built concurrently/online
    add NOT NULL, foreign key, check constraintfull-table validation, may lock
    rename or drop column or tablebreaks running code
    change typetable rewrite on many engines
  2. Apply expand–contract. Expand: add the new structure alongside the old. Migrate: deploy code that writes both and reads new with fallback; backfill. Contract: after every instance runs the new code, remove the old structure in a later release.
  3. Use online operations. PostgreSQL: CREATE INDEX CONCURRENTLY, ADD CONSTRAINT … NOT VALID followed by VALIDATE CONSTRAINT, set lock_timeout so a migration fails fast instead of queueing behind long transactions. MySQL: online DDL or a tool such as gh-ost or pt-online-schema-change.
  4. Backfill in batches. Batches by primary-key range (for example 1–10k rows), commit per batch, throttle, make it resumable and idempotent, and monitor replication lag.
  5. Plan rollback. For each step write the down-path. Irreversible steps (drops, lossy type changes) need a backup or an export of the affected data, verified restorable.
  6. Rehearse on a production-sized copy: measure duration and locks, and check the query plans of critical queries.
  7. Release and observe. Error rate, latency, locks and replication lag during and after; proceed to contract only after a stable period.

Example fixture

-- Rename users.fullname -> users.display_name without downtime
ALTER TABLE users ADD COLUMN display_name text;            -- release 1 (expand)
-- app writes both, reads display_name with fallback to fullname
UPDATE users SET display_name = fullname
 WHERE id BETWEEN $1 AND $2 AND display_name IS NULL;      -- batched backfill
-- release 2: app reads/writes display_name only
ALTER TABLE users DROP COLUMN fullname;                    -- release 3 (contract)

Common rationalizations

RationalizationReality
The table is small, locking is fine.Tables grow, and even a small table blocks every query queued behind a long transaction. Set lock_timeout and measure.
We'll roll back if it breaks.Many schema changes (drops, lossy type changes) cannot be rolled back without a backup. Plan the down-path first.
We can rename the column in one release.Running instances of the old version will fail. Use expand–contract across releases.

Acceptance checks

  • No step breaks the currently deployed application version.
  • Long-locking statements are replaced by online variants or scheduled with explicit approval.
  • Backfill is idempotent and resumable; batch size and duration were measured.
  • Rollback is documented per step; irreversible steps have a verified backup.

Output

Ordered migration plan across releases, scripts, rehearsal measurements and a rollback plan.

Safety

Never run migrations against production without approval and a fresh backup. Do not drop data "because it seems unused" without evidence of no reads.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.