What does this skill do?

The Secure Database Migrations Skill provides proven patterns for performing schema changes and data migrations in production databases in a secure, reversible, and service-continuous manner. It covers PostgreSQL, MySQL, and popular ORMs such as Prisma, Django, and golang-migrate, and includes the “expand-contract” pattern for critical deployments with zero downtime.

Changes to the production plan
Create or modify tables, add columns and indexes without locking the database or interrupting service.
Batch Data Migrations
Perform backfills and bulk transformations in blocks using SKIP LOCKED to avoid long locks.
Expand-Contract Pattern
Rename or transform columns in three steps: add, fill, and delete—without disrupting the application.
Configuring ORMs
Set up migration tools for new projects using Prisma, Django, Drizzle, Kysely, or golang-migrate.

Usage examples

🏗️ Add a secure column
I need to add an `avatar_url` column to the `users` table in PostgreSQL without locking the table. Generate the migration.
🔄 Rename Column
I want to rename the "username" column to "display_name" in production using the expand-contract pattern. Give me the migrations.
📦 Batch Backfill
I need to backfill `normalized_email = LOWER(email)` for 2 million rows. Generate the migration in batches.
🛠️ Workflow with Prisma
Set up the migration workflow with Prisma for my project: create, apply, and generate custom SQL.

Features

Reversible Migration Each migration includes clearly defined UP and DOWN operations for a safe rollback.
Zero production stoppages Use CREATE INDEX CONCURRENTLY, nullable columns with defaults, and batch operations with SKIP LOCKED.
Expand-Contract Pattern Seamless deployment in three phases: add, fill in data, and remove obsolete items.
Separation of Schema and Data DDL and DML migrations are stored in separate files to facilitate rollback and avoid long transactions.
Multi-ORM and multi-engine Compatible with PostgreSQL, MySQL, Prisma, Django, Drizzle, Kysely, and golang-migrate.

Frequently asked questions

Mainly PostgreSQL and MySQL, with specific examples for each database engine. The patterns are applicable to any relational database.
No. The skill provides templates and ready-to-use SQL code that works with your preferred ORM or migration tool (Prisma, Django, golang-migrate, etc.).
Yes. The patterns are specifically designed to prevent deadlocks in large tables by using concurrent operations, nullable columns with default values, and batch backfills.
Yes, but never edit a migration that has already been deployed to production. Create a new migration to prevent drift between environments.
Secure Database Migrations — Seamless Deployments with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.