database-migration
Database migration best practices — schema changes, zero-downtime migrations, rollback strategies, and data migration patterns.
Skill by Claude-Code-Community-Ireland
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/claude-code-community-ireland-database-migration
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, data
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/database-migration
What's inside
- Skill name
database-migration- Description
- Database migration best practices — schema changes, zero-downtime migrations, rollback strategies, and data migration patterns. Reference when modifying database schemas.
- License
- MIT
- Instructions
- 346 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Database Migration
## Migration File Conventions
Every schema change must be captured in a versioned migration file. Follow these conventions:
- **Timestamped naming**: Use `YYYYMMDDHHMMSS_descriptive_name` (e.g., `20240315143022_add_status_to_orders.sql`).
- **Sequential ordering**: Migrations run in order. Never insert a migration before one that has already been applied.
- **One concern per file**: Each migration handles a single logical change. Do not combine unrelated schema changes.
- **Descriptive names**: The filename should describe the change, not the ticket number. Use verbs like `add`, `remove`, `create`, `drop`, `rename`, `alter`.
- **Idempotent when possible**: Use `IF NOT EXISTS` / `IF EXISTS` guards to make re-runs safe.
```
migrations/
20240301100000_create_users_table.sql
20240305120000_add_email_index_to_users.sql
20240310090000_create_orders_table.sql
20240315143022_add_status_to_orders.sql
```
## Forward and Rollback Pairs
Every migration must have a corresponding rollback. If you cannot write a safe rollback, document why and flag it for review.
```sql
-- Migration: 20240315143022_add_status_to_orders.sql
-- UP
ALTER TABLE orders ADD COLUMN status VARCHAR(50) DEFAULT 'pending';
CREATE INDEX idx_orders_status ON orders (status);
-- DOWN
DROP INDEX IF EXISTS idx_orders_status;
ALTER TABLE orders DROP COLUMN IF EXISTS status;
```
### Rollback Rules
| Scenario | Rollback Strategy |
|----------|-------------------|
| Add column | Drop column |
| Add index | Drop index |
| Create table | Drop table |
| Add constraint | Drop constraint |
| Rename column | Rename back |
| Drop column | Cannot auto-rollback — must restore from backup or use prior migration to re-add |
| Data backfill | Reverse backfill or accept data state |
## Zero-Downtime Schema Changes
When your application cannot tolerate downtime during deploys, follow the expand-and-contract pattern. Never make breaking schema changes in a single step.
### Step-by-Step: Renaming a Column
Renaming a column directly (`ALTER TABLE ... RENAME COLUMN`) breaks running application instances that reference the old name. Instead:
1. **Deploy 1 — Expand**: Add the new column alongside the old one.
```sql
ALTER TABLE users ADD COLUMN full_name VARCHAR(255);
```
2. **Deploy 2 — Dual Write**: Update application code to write to both columns.
```javascript
// Write to both columns
await db.query(
'UPDATE users SET name = $1, full_name = $1 WHERE id = $2',
[name, userId]
);
```
3. **Deploy 3 — Backfill**: Copy existing data from old column to new column.
```sql
UPDATE users SET full_name = name WHERE full_name IS NULL;
```
4. **Deploy 4 — Cut Over**: Update application to read from and write to new column only.
```javascript
// Read from new column
const user = await db.query('SELECT full_name FROM users WHERE id = $1', [userId]);
```
5. **Deploy 5 — Contract**: Drop the old column after a safe observation period.
```sql
ALTER TABLE users DROP COLUMN name;
```
### Step-by-Step: Adding a NOT NULL Constraint
Adding a `NOT NULL` constraint on an existing column with null values will fail or lock the table. Safe approach:
1. Add a check constraint as `NOT VALID` (PostgreSQL) to avoid scanning existing rows:
```sql
ALTER TABLE orders ADD CONSTRAINT orders_status_not_null
CHECK (status IS NOT NULL) NOT VALID;
```
2. Backfill any null values:
```sql
UPDATE orders SET status = 'unknown' WHERE status IS NULL;
```
3. Validate the constraint (acquires lighter lock):
```sql
ALTER TABLE orders VALIDATE CONSTRAINT orders_status_not_null;
```
4. Optionally convert to a proper `NOT NULL` column constraint:
```sql
ALTER TABLE orders ALTER COLUMN status SET NOT NULL;
ALTER TABLE orders DROP CONSTRAINT orders_status_not_null;
```
## Dangerous Operations
| Operation | Risk | Safe Alternative |
|-----------|------|-----------------|
| `RENAME COLUMN` | Breaks queries referencing old name | Expand-and-contract pattern (add new, migrate, drop old) |
| `CHANGE COLUMN TYPE` | May require full table rewrite, long lock | Add new column with new type, backfill, swap |
| `DROP COLUMN` | Irreversible data loss | Verify no code references, back up data, then drop |From Claude-Code-Community-Ireland/claude-code-resources, MIT.
More from Claude-Code-Community-Ireland/claude-code-resources
- 0.477score
start-of-day
Claude-Code-Community-Ireland
Comprehensive daily project sync - checks git repos, analyzes all code, reads documentation, and provides status report.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
performance-profiling
Claude-Code-Community-Ireland
Performance analysis methodology — identifying bottlenecks, profiling techniques, benchmarking, and common optimization patterns.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
finish-the-day
Claude-Code-Community-Ireland
End-of-day wrap up - analyzes all work done, creates detailed daily update log, commits all changes, and pushes to remote.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
incident-response
Claude-Code-Community-Ireland
Incident response procedures — triage, communication, investigation, mitigation, and post-incident review.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
tdd-workflow
Claude-Code-Community-Ireland
Test-driven development methodology — red-green-refactor cycle, writing failing tests first, minimal implementation, and iterative refinement.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
debugging-systematic
Claude-Code-Community-Ireland
Systematic debugging methodology — binary search isolation, hypothesis-driven debugging, reproducing issues, and root cause analysis.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
dependency-audit
Claude-Code-Community-Ireland
Dependency management and auditing — evaluating new dependencies, security vulnerability scanning, update strategies, and license compliance.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
architecture-decision-record
Claude-Code-Community-Ireland
ADR format and methodology for documenting significant technical decisions with context, alternatives considered, and consequences.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
community-code-reviewer
Claude-Code-Community-Ireland
Perform thorough, constructive code reviews on pull requests and code changes.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
discord
Claude-Code-Community-Ireland
Manage your Discord server - post announcements, create events, moderate, and more.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
conventional-commits
Claude-Code-Community-Ireland
Generate well-formatted conventional commit messages from staged changes.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
refactoring-patterns
Claude-Code-Community-Ireland
Safe refactoring techniques — extract method, rename, move, inline, and structural patterns.
SkillDFreshness: D★ 11Claude Code +9
Signals
- Stars
- 11
- Forks
- 4
- Open issues
- 4
- Last commit (this folder)
- Jan 29, 2026 (9 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from Claude-Code-Community-Ireland
- 0.477score
debugging-systematic
Claude-Code-Community-Ireland
Systematic debugging methodology — binary search isolation, hypothesis-driven debugging, reproducing issues, and root cause analysis.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
dependency-audit
Claude-Code-Community-Ireland
Dependency management and auditing — evaluating new dependencies, security vulnerability scanning, update strategies, and license compliance.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
architecture-decision-record
Claude-Code-Community-Ireland
ADR format and methodology for documenting significant technical decisions with context, alternatives considered, and consequences.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
community-code-reviewer
Claude-Code-Community-Ireland
Perform thorough, constructive code reviews on pull requests and code changes.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
conventional-commits
Claude-Code-Community-Ireland
Generate well-formatted conventional commit messages from staged changes.
SkillDFreshness: D★ 11Claude Code +9 - 0.477score
discord
Claude-Code-Community-Ireland
Manage your Discord server - post announcements, create events, moderate, and more.
SkillDFreshness: D★ 11Claude Code +9
Cite this page
database-migration skill. Agent Mart. https://agentmart.dev/skills/claude-code-community-ireland-database-migration (last updated 2026-10-24)