database-migrations
Skill1 starsChanged 6 months agoMITView on GitHub
Database migration best practices for schema changes, data migrations, rollbacks, and zero-downtime deployments using Flyway with PostgreSQL/MySQL and Spring Boot.
52 other projects use a version of this, 30 of them edited.
Adopted by
Most recently taken up by
- Rojios/everything-claude-codeedited, first seen Nov 8, 2026
- lhbsaa/apex-unifiededited, first seen Nov 8, 2026
- profdorly/ultimate-dev-skillstheir own version, first seen Nov 8, 2026
- ahmadvahidi/skill-atlasedited, first seen Nov 8, 2026
- LeanMeanCleanApps/CleanModelContextProtocoltheir own version, first seen Nov 8, 2026
- reddygopalkrishna/developer-agent-skillstheir own version, first seen Nov 8, 2026
Used with
Projects with it also use deployment-patterns, postgres-patterns and 6 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.
royaluniondesign-sysSkilldeployment-patterns
Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications.
Also in 6 projects that use this
nek1987Skillpostgres-patterns
PostgreSQL patterns for reviewing migrations and writing efficient queries. Use when reviewing Alembic migrations, optimizing queries, or debugging database issues.
Also in 7 projects that use this
HABUBUSSSkillbackend-patterns
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Also in 9 projects that use this
SentrySkillreact-testing
Write and review React/TypeScript tests for Sentry's frontend using Jest and React Testing Library. Use when adding or editing tests in static/ (*.spec.tsx), writing component/hook tests, mocking API responses with MockApiClient, testing routing or network requests, or when asked to "write a frontend test", "add a React test", "test this component", or "fix a flaky RTL test".
Also in 3 projects that use this
xenitV1Skillreact-patterns
Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.
Also in 4 projects that use this
junimnjwSkillagent-harness-construction
Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates.
Also in 3 projects that use this
Other versions52 projects use a version of this.
Word for word · 0
None found.
Edited · 30
- loulanyue/awesome-claude-notes★ 27246% same
- Fmarzochi/EGC★ 6146% same
- skateddu/claude-code-python-setup★ 2854% same
- gongyijie85/dsh-ecc★ 846% same
- zero-click/zero-ratchet★ 846% same
- chadixearth/graphyloop★ 344% same
- TsinHzl/claude-code-config★ 211% same
- balu-16/skills★ 145% same
- get-proofpilot/claude-skills-catalog★ 157% same
- JameMy0001/antigravity-skills-hub★ 141% same
20 more not listed
Wrote their own version · 22
- langchain-ai/skills-benchmarks★ 116same name
- wpank/ai★ 11same name
- reddygopalkrishna/developer-agent-skills★ 8same name
- sponge-b0b/Polaris★ 4same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
- nafeeur/MaskShift★ 2same name
- impeto-ai/claude-skills-impeto★ 1same name
- kennguyen887/agent-foundation★ 1same name
- KMaruthi2002/universal-llm-skills★ 1same name
- LeanMeanCleanApps/CleanModelContextProtocol★ 1same name
12 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 repository20 other files it gives its agents.
- finishing-a-development-branchSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- systematic-debuggingSkill
- verification-before-completionSkill
- api-designSkill
- fastapi-patternsSkill
- logging-standardsSkill
- python-patternsSkill
- redis-patternsSkill
- springboot-patternsSkill
- security-reviewSkill
- using-superpowersSkill
- java-testingSkill
- python-testingSkill
- test-driven-developmentSkill
- brainstormingSkill
- executing-plansSkill
- subagent-driven-developmentSkill
- writing-plansSkill
The file
We split this skill into the rules it gives an agent
3 rules. 1 is common, 1 is distinctive, and 1 is very specific to this project.
1
Common
Most of the 48 edited versions we read keep these.
1
Distinctive
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
- Common: line 28
Before applying any migration:
- Distinctive: line 69
Never rename directly in production.
- Very specific: line 193
Use
flywayRepaironly: when a migration failed mid-run and left a dirty state
“Common” is measured: kept by at least 6 in 10 of the 48 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 Migration Patterns
Safe, reversible database schema changes for production systems.
When to Activate
- Creating or altering database tables
- Adding/removing columns or indexes
- Running data migrations (backfill, transform)
- Planning zero-downtime schema changes
- Setting up migration tooling for a new project
Core Principles
- Every change is a migration — never alter production databases manually
- Migrations are forward-only in production — rollbacks use new forward migrations
- Schema and data migrations are separate — never mix DDL and DML in one migration
- Test migrations against production-sized data — a migration that works on 100 rows may lock on 10M
- Migrations are immutable once deployed — never edit a migration that has run in production
Migration Safety Checklist
Before applying any migration:
- Migration has both UP and DOWN (or is explicitly marked irreversible)
- No full table locks on large tables (use concurrent operations)
- New columns have defaults or are nullable (never add NOT NULL without default)
- Indexes created concurrently (not inline with CREATE TABLE for existing tables)
- Data backfill is a separate migration from schema change
- Tested against a copy of production data
- Rollback plan documented
PostgreSQL Patterns
Adding a Column Safely
-- GOOD: Nullable column, no lock
ALTER TABLE users ADD COLUMN avatar_url TEXT;
-- GOOD: Column with default (Postgres 11+ is instant, no rewrite)
ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT true;
-- BAD: NOT NULL without default on existing table (requires full rewrite)
ALTER TABLE users ADD COLUMN role TEXT NOT NULL;
-- This locks the table and rewrites every rowAdding an Index Without Downtime
-- BAD: Blocks writes on large tables
CREATE INDEX idx_users_email ON users (email);
-- GOOD: Non-blocking, allows concurrent writes
CREATE INDEX CONCURRENTLY idx_users_email ON users (email);
-- Note: CONCURRENTLY cannot run inside a transaction block
-- Most migration tools need special handling for thisRenaming a Column (Zero-Downtime)
Never rename directly in production. Use the expand-contract pattern:
-- Step 1: Add new column (migration 001)
ALTER TABLE users ADD COLUMN display_name TEXT;
-- Step 2: Backfill data (migration 002, data migration)
UPDATE users SET display_name = username WHERE display_name IS NULL;
-- Step 3: Update application code to read/write both columns
-- Deploy application changes
-- Step 4: Stop writing to old column, drop it (migration 003)
ALTER TABLE users DROP COLUMN username;Removing a Column Safely
-- Step 1: Remove all application references to the column
-- Step 2: Deploy application without the column reference
-- Step 3: Drop column in next migration
ALTER TABLE orders DROP COLUMN legacy_status;Large Data Migrations
-- BAD: Updates all rows in one transaction (locks table)
UPDATE users SET normalized_email = LOWER(email);
-- GOOD: Batch update with progress
DO $$
DECLARE
batch_size INT := 10000;
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 batch_size
FOR UPDATE SKIP LOCKED
);
GET DIAGNOSTICS rows_updated = ROW_COUNT;
RAISE NOTICE 'Updated % rows', rows_updated;
EXIT WHEN rows_updated = 0;
COMMIT;
END LOOP;
END $$;Flyway (Java / Spring Boot)
Setup (build.gradle)
dependencies {
implementation 'org.flywaydb:flyway-core'
// For MySQL: also add flyway-mysql
implementation 'org.flywaydb:flyway-mysql'
}# application.yml
spring:
flyway:
enabled: true
locations: classpath:db/migration
baseline-on-migrate: falseNaming Convention
V{version}__{description}.sql ← versioned migration (runs once)
R__{description}.sql ← repeatable migration (runs when changed)
U{version}__{description}.sql ← undo migration (Flyway Teams only)Examples:
V1__create_users_table.sql
V2__add_avatar_url_to_users.sql
V3__backfill_display_name.sql
R__create_views.sqlWorkflow Commands
# Apply pending migrations (also runs automatically on app startup)
./gradlew flywayMigrate
# Check migration status
./gradlew flywayInfo
# Validate migrations match checksums
./gradlew flywayValidate
# Repair failed migration (fix checksum mismatch or mark as failed)
./gradlew flywayRepair
# Clean all objects (dev only — NEVER in production)
./gradlew flywayCleanMigration File Example
-- src/main/resources/db/migration/V2__add_avatar_url_to_users.sql
ALTER TABLE users ADD COLUMN avatar_url VARCHAR(500);
-- src/main/resources/db/migration/V3__add_email_index.sql
-- For MySQL, use standard CREATE INDEX (no CONCURRENTLY)
CREATE INDEX idx_users_email ON users (email);Flyway Rules
- Never edit a deployed migration file — Flyway validates checksums; any edit causes
FlywayValidationException - Use
flywayRepaironly when a migration failed mid-run and left a dirty state flywayCleanis destructive — disable in production withspring.flyway.clean-disabled=true- Separate schema and data — DDL changes and data backfills must be separate migration files
Zero-Downtime Migration Strategy
For critical production changes, follow the expand-contract pattern:
Phase 1: EXPAND
- Add new column/table (nullable or with default)
- Deploy: app writes to BOTH old and new
- Backfill existing data
Phase 2: MIGRATE
- Deploy: app reads from NEW, writes to BOTH
- Verify data consistency
Phase 3: CONTRACT
- Deploy: app only uses NEW
- Drop old column/table in separate migrationTimeline Example
Day 1: Migration adds new_status column (nullable)
Day 1: Deploy app v2 — writes to both status and new_status
Day 2: Run backfill migration for existing rows
Day 3: Deploy app v3 — reads from new_status only
Day 7: Migration drops old status columnAnti-Patterns
| Anti-Pattern | Why It Fails | Better Approach |
| Manual SQL in production | No audit trail, unrepeatable | Always use migration files |
| Editing deployed migrations | Causes drift between environments | Create new migration instead |
| NOT NULL without default | Locks table, rewrites all rows | Add nullable, backfill, then add constraint |
| Inline index on large table | Blocks writes during build | CREATE INDEX CONCURRENTLY |
| Schema + data in one migration | Hard to rollback, long transactions | Separate migrations |
| Dropping column before removing code | Application errors on missing column | Remove code first, drop column next deploy |
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.

