Skip to content
Back to skills

Database Migrations

ASecurity

Use when database migration best practices for schema changes, data migrations, rollbacks, and zero-downtime deployments across PostgreSQL, MySQL, and common ORMs (Prisma, Drizzle, Kysely, Django, TypeORM, golang-migrate). Triggers on \"database-migrations\", \"database migrations\", \"migrations\".

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 19, 2026
databasesgosqldjangodatabase

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned September 19, 2026

npx -y skills add majinmagros/magros.ai-skills --skill database-migrations --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database Migrations?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database Migrations
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majinmagros-database-migrations/badge)](https://www.skillsdirectory.com/skills/majinmagros-database-migrations)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: database-migrations
description: "Use when database migration best practices for schema changes, data migrations, rollbacks, and zero-downtime deployments across PostgreSQL, MySQL, and common ORMs (Prisma, Drizzle, Kysely, Django, TypeORM, golang-migrate). Triggers on \"database-migrations\", \"database migrations\", \"migrations\"."
metadata:
  origin: ECC
---

# Database Migration Patterns

Safe, reversible schema changes: forward-only in production, schema and data migrations separate, expand-contract for renames. Detalhes em `references/`.

## 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

1. **Every change is a migration** — never alter production manually
2. **Forward-only in production** — rollbacks are new forward migrations
3. **Schema and data separate** — never mix DDL and DML
4. **Test at production scale** — 100 rows OK can lock at 10M
5. **Immutable once deployed** — never edit a ran migration

## Safety Checklist

- [ ] UP and DOWN (or explicitly irreversible)
- [ ] No full table locks (concurrent ops on large tables)
- [ ] New columns nullable or with default
- [ ] Indexes via `CONCURRENTLY`, backfill in separate migration
- [ ] Tested on production-data copy, rollback plan documented

## Example

```sql
-- Safe: nullable first, no lock, no rewrite
ALTER TABLE users ADD COLUMN avatar_url TEXT;

-- Unsafe: NOT NULL without default rewrites every row
-- ALTER TABLE users ADD COLUMN role TEXT NOT NULL;
```

## References

- `references/postgres-patterns.md` — safe ADD COLUMN, concurrent index, rename/drop, batched backfill
- `references/orms-ts.md` — Prisma, Drizzle, Kysely workflows + migration files
- `references/orms-py-go.md` — Django data migrations, SeparateDatabaseAndState, golang-migrate
- `references/zero-downtime.md` — expand-contract phases, timeline, anti-patterns table

Files in this skill

  • SKILL.md2 KB
  • references/orms-py-go.md2.3 KB
  • references/orms-ts.md4.1 KB
  • references/postgres-patterns.md2.3 KB
  • references/zero-downtime.md1.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…