Zero-downtime schema migrations — expand/contract, backward compatibility with the running release, online index creation, batched backfills with throttling, constraint validation, lock timeouts, rollback notes, migration tooling. Use for any schema or data migration (migration, expand contract, backfill, zero downtime, schema change).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Database Migrations?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/vectora-os-database-migrations)
---
name: database-migrations
description: Zero-downtime schema migrations — expand/contract, backward compatibility with the running release, online index creation, batched backfills with throttling, constraint validation, lock timeouts, rollback notes, migration tooling. Use for any schema or data migration (migration, expand contract, backfill, zero downtime, schema change).
metadata:
category: data
---
# Database migrations
## Purpose
Change schemas without downtime and with a way back.
**Use when:** every schema or data migration.
**Not for:** logical model design.
## Inputs
- Current and target schema, table sizes, release plan.
## Outputs
- Migration scripts, backfill plan, rollback notes, checklist.
## Read first
- [Project Brain](../../../project-brain/README.md) — `npm run brain -- query "database migrations"` for prior decisions, patterns and anti-patterns.
- [Migration review checklist](../../../checklists/migration-review.md)
## Steps
1. **Expand.** Additive changes compatible with the current code.
Done when old code works with new schema.
2. **Backfill.** Batched, throttled, idempotent, resumable.
Done when backfill measured on a copy.
3. **Switch.** Code reads/writes new structure behind a flag.
Done when flag can revert.
4. **Contract.** Remove old structures in a later release.
Done when no code references them.
## Best practices
- Set `lock_timeout` and `statement_timeout` in migrations.
- Never rename in place.
## Common mistakes
- Adding NOT NULL with default on huge tables in old engines.
- Migration and code change that only work together.
## Example
Rename `email` → `email_address`: add column, dual-write, backfill, switch reads, drop old column next release.
## Reusable prompt
```text
Apply the Database migrations skill (.agents/skills/database-migrations/SKILL.md).
Context: {{task card or question; links to PRD, ADRs, code paths}}
Constraints: {{approved thresholds, deadlines, allowed files}}
Plan the migration as expand, backfill, switch, contract with timings, lock safety and rollback per step.
Return: Migration scripts, backfill plan, rollback notes, checklist..
Cite evidence (file:line, command output, source) for every claim; list open questions separately.
```