database-migrations
Skill1 starsChanged 57 days agoMITView on GitHub
Safe, reversible schema and data migrations for production databases, covering lock-free column and index changes, expand-contract renames, batched backfills, explicit constraint names, rollback strategy, and the review gates a migration must pass. Use when you say "add a column to this table", "create this index without downtime", "rename a column safely", "backfill ten million rows", or "how do we roll this migration back". Not for index choice and query tuning, use `postgres-patterns`.
33 other projects use a version of this.
Adopted by
Most recently taken up by
- JameMy0001/antigravity-skills-hubtheir own version, first seen Oct 2, 2026
- productionx-in/Core-Skillstheir own version, first seen Sep 29, 2026
- lintangknitto/agent-skillstheir own version, first seen Sep 23, 2026
- templetongroup/radianttheir own version, first seen Sep 17, 2026
- MortuisVMain/ai-agent-superpowerstheir own version, first seen Sep 15, 2026
- nafeeur/MaskShifttheir own version, first seen Sep 12, 2026
Used with
Projects with it also use autonomous-loops and iterative-retrieval.
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.
InfopibeSkillautonomous-loops
Patterns and architectures for autonomous Claude Code loops — from simple sequential pipelines to RFC-driven multi-agent DAG systems.
Also in 3 projects that use this
Microsoft AzureSkilliterative-retrieval
Max-3-cycle protocol for agent sub-tasks with WHY context and coordinator validation. Use when spawning sub-agents to complete scoped work.
Also in 3 projects that use this
Other versions33 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 33
- xu-xiang/everything-claude-code-zh★ 2ksame name
- loulanyue/awesome-claude-notes★ 272same name
- tpavanipradeep/everything-claude-code★ 134same name
- langchain-ai/skills-benchmarks★ 118same name
- templetongroup/radiant★ 113same name
- Jamkris/everything-gemini-code★ 87same name
- skateddu/claude-code-python-setup★ 28same name
- noah-sheldon/ai-dev-kit★ 13same name
- wpank/ai★ 11same name
- vanara-agents/skills★ 9same name
23 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.
In this repository59 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- agentic-engineeringSkill
- ai-regression-testingSkill
- angularSkill
- ansibleSkill
- api-designSkill
- architecture-decision-recordsSkill
- ascend-memorySkill
- ascend-web-hunterSkill
- audio-scribeSkill
- automation-inventorySkill
- backend-patternsSkill
- bashSkill
- build-dependency-managementSkill
- code-formatterSkill
- code-reviewerSkill
- coding-standardsSkill
- dart-flutter-patternsSkill
- deployment-patternsSkill
- design-systemSkill
- docker-patternsSkill
- e2e-runbooksSkill
- e2e-testingSkill
- embedded-c-arduinoSkill
- frontend-designSkill
- g-code-3d-printingSkill
- github-opsSkill
- git-workflowSkill
- golang-patternsSkill
- hexagonal-architectureSkill
- home-assistantSkill
- java-coding-standardsSkill
- jetbrains-ide-opsSkill
- jira-integrationSkill
- keycloak-patternsSkill
- kicadSkill
- markdown-writerSkill
- mongodb-patternsSkill
- nextjs-app-router-patternsSkill
- node-backend-patternsSkill
- observability-and-loggingSkill
- obsidianSkill
- performance-optimizationSkill
- postgres-patternsSkill
- powershellSkill
- project-trackingSkill
- python-patternsSkill
- pytorch-patternsSkill
- react-patternsSkill
- researchSkill
- review-duplicationSkill
- security-reviewSkill
- seoSkill
- soap-webservicesSkill
- springboot-patternsSkill
- tdd-workflowSkill
- unitySkill
- web-accessibilitySkill
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 30 edited versions we read keep these.
3
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
- Distinctive: line 51
Every change is a migration.
- Distinctive: line 54
Test against production-sized data.
- Distinctive: line 198
Keep the preview as a CI artifact, and require a database owner to sign off whenever the change touches a table over a million rows.
“Common” is measured: kept by at least 6 in 10 of the 30 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
Database Migrations
Rules for changing a schema that is already carrying production traffic, where the failure mode is a locked table rather than a compile error. The tool-specific commands live in the references. This file is the safety model every tool has to satisfy.
Baseline versions, current as of September 2026: PostgreSQL 18, MySQL 8.4 LTS, and the migration tools named in the reference map below.
When to activate
- Creating or altering a table, column, index, or constraint on a live database.
- Backfilling or transforming existing rows.
- Planning a schema change that must survive a rolling deploy.
- Choosing or configuring migration tooling on a new project.
- Reviewing a migration before it reaches a production database.
When not to activate
- Choosing an index type, reading a query plan, or tuning a slow query: use
postgres-patterns. - MongoDB document model and schema versioning: use
mongodb-patterns. - JPA and Hibernate entity mapping above the schema: use
springboot-patterns. - Deploy orchestration and rollback of the application itself: use
deployment-patterns. - Backup, restore, and retention policy: use
postgres-patterns.
Reference map
| Tool | Open |
| Prisma | references/prisma.md |
| Drizzle | references/drizzle.md |
| Kysely | references/kysely.md |
| Django | references/django.md |
| golang-migrate | references/golang-migrate.md |
Core principles
- Every change is a migration. Never alter a production database by hand.
- Production is forward-only. A rollback is a new forward migration, not a re-run of a down file.
- Schema and data changes are separate migrations. Never mix DDL and DML in one file.
- Test against production-sized data. A migration that runs on 100 rows can lock on 10 million.
- A deployed migration is immutable. Editing one that has already run produces drift between environments.
Add a column without rewriting the table
-- PASS: nullable column, metadata-only change
ALTER TABLE users ADD COLUMN avatar_url TEXT;
-- PASS: PostgreSQL 11 or newer stores a constant default in the catalogue, so no rewrite happens
ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT true;
-- FAIL: NOT NULL with no default on an existing table rewrites every row under an exclusive lock
ALTER TABLE users ADD COLUMN role TEXT NOT NULL;To reach a NOT NULL column with no sensible default, take three steps: add it nullable, backfill in batches, then add
the constraint as NOT VALID and VALIDATE CONSTRAINT separately, which takes a weaker lock.
Build indexes concurrently
-- PASS
CREATE INDEX CONCURRENTLY idx_users_email ON users (email);
-- FAIL: blocks every write to the table for the duration of the build
CREATE INDEX idx_users_email ON users (email);CONCURRENTLY cannot run inside a transaction block, and most migration tools wrap each file in one, so the statement
needs its own migration and usually a tool-specific opt-out. A concurrent build that fails leaves an invalid index
behind: check pg_index.indisvalid and drop it before retrying.
Rename with expand and contract, never in place
A rename is instantaneous for the database and fatal for the running application, because the old code and the new schema overlap during any rolling deploy.
-- 001 expand: add the new column
ALTER TABLE users ADD COLUMN display_name TEXT;
-- 002 backfill: separate data migration, batched
UPDATE users SET display_name = username WHERE display_name IS NULL;
-- deploy the application version that writes both and reads the new column
-- 003 contract: drop the old column once nothing references it
ALTER TABLE users DROP COLUMN username;Dropping a column follows the same order in reverse: remove every application reference, deploy, then drop.
Backfill in bounded batches
-- FAIL: one transaction over every row, holding locks and bloating the WAL
UPDATE users SET normalized_email = LOWER(email);-- PASS: bounded batches, each committed, skipping rows another worker holds
DO $$
DECLARE
rows_updated INT;
BEGIN
LOOP
UPDATE users SET normalized_email = LOWER(email)
WHERE id IN (
SELECT id FROM users WHERE normalized_email IS NULL
LIMIT 10000 FOR UPDATE SKIP LOCKED
);
GET DIAGNOSTICS rows_updated = ROW_COUNT;
EXIT WHEN rows_updated = 0;
COMMIT;
END LOOP;
END $$;Make the batch resumable by selecting on the condition the update clears, so a killed backfill can simply be restarted.
Name every constraint explicitly
An auto-generated name differs between environments and cannot be dropped reliably in a later migration.
ALTER TABLE orders
ADD CONSTRAINT ck_orders_amount_positive CHECK (amount > 0),
ADD CONSTRAINT uq_orders_reference UNIQUE (reference_number),
ADD CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers(id);
CREATE INDEX idx_orders_status ON orders (status) WHERE status != 'completed';Prefixes: ck_ check, uq_ unique, fk_ foreign key, idx_ index.
Give every Liquibase changeset a rollback block
<changeSet id="20240101-add-status-column" author="dev">
<addColumn tableName="orders">
<column name="status" type="VARCHAR(20)" defaultValue="pending">
<constraints nullable="false"/>
</column>
</addColumn>
<rollback>
<dropColumn tableName="orders" columnName="status"/>
</rollback>
</changeSet>Liquibase infers a rollback for some operations and silently does nothing for others, so write the block even when it
looks redundant. Use context to scope a changeset to an environment, for example seed data that must never reach
production.
Preview the SQL before a production run
Generate the statements a run will execute and attach them to the change for review.
liquibase --changeLogFile=changelog.xml updateSQL > migration_preview.sqlFlyway offers the same thing through -dryRunOutput, but that flag is part of Flyway Teams and Enterprise, not the
community edition. On community Flyway, review the migration files themselves and rely on the staging run instead.
flyway -url=jdbc:postgresql://prod/db -dryRunOutput=migration_preview.sql migrateKeep the preview as a CI artifact, and require a database owner to sign off whenever the change touches a table over a million rows.
Run EXPLAIN ANALYZE before the change lands
Two triggers, either one of which requires the plan in the change description:
- Any migration that touches data in an existing table, meaning
UPDATE,DELETE,INSERT ... SELECT, or a concurrent index build. - Any query expected to touch more than 10,000 rows.
EXPLAIN ANALYZE executes the statement it plans, so on an UPDATE, DELETE or INSERT it changes the data. Run
it inside a transaction and roll back:
BEGIN;
EXPLAIN ANALYZE UPDATE orders SET status = 'active' WHERE created_at > '2024-01-01';
ROLLBACK;This is the same gate postgres-patterns states for query changes, deliberately worded identically so a change that
crosses both skills is reviewed once against one rule.
Anti-patterns
| Anti-pattern | Why it fails | Instead |
| Manual SQL in production | No audit trail, unrepeatable | Always a migration file |
| Editing a deployed migration | Environments drift silently | Write a new migration |
| NOT NULL with no default | Exclusive lock, full rewrite | Nullable, backfill, then validate |
| Inline index on a large table | Blocks writes during the build | CREATE INDEX CONCURRENTLY |
| Schema and data in one file | Long transaction, hard to roll back | Separate migrations |
| Dropping a column before removing the code | The running release errors | Remove references, deploy, then drop |
| Migration on application startup | Concurrent replicas race each other | One migration step in the deploy pipeline |
Related skills
postgres-patternsfor index choice, query plans, and the matching EXPLAIN ANALYZE gate.springboot-patternsfor the JPA entity mapping that has to move with the schema.mongodb-patternsfor the document-model equivalent of these changes.deployment-patternsfor sequencing a migration inside a rolling deploy.backend-patternsfor keeping an application readable across an expand-contract window.
Checklist
- The migration has a down file, or is explicitly documented as irreversible.
- No statement takes a lock that blocks writes on a large table.
- New columns are nullable or carry a constant default.
- Indexes on existing tables are built concurrently, in their own migration.
- Renames and drops follow expand and contract across at least two deploys.
- Backfills are batched, committed per batch, and resumable.
- Every constraint and index has an explicit, prefixed name.
- The migration was run against a copy of production-sized data.
EXPLAIN ANALYZEoutput is attached when either trigger above applies.- The rollback path is written down, not assumed.
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.

