database-migrations

Guide safe, reversible database schema and data migrations across SQL and ORMs.

Updated May 24, 2023
One-click install
npx skills add https://github.com/Kimjiman/basic-arch --skill database-migrations-kimjiman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-migrations
Source: https://github.com/Kimjiman/basic-arch/tree/main/.claude/skills/database-migrations
Command: npx skills add https://github.com/Kimjiman/basic-arch --skill database-migrations-kimjiman

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and best practices for managing database schema changes, data migrations, and rollbacks safely and efficiently in production environments.

Core Features & Use Cases

  • Schema Evolution: Safely add/remove columns, tables, and indexes.
  • Data Migration: Handle complex data transformations and backfills.
  • Zero-Downtime Deployments: Implement strategies for seamless schema updates without service interruption.
  • Tooling Integration: Covers patterns for PostgreSQL, MySQL, Prisma, Drizzle, Django, and golang-migrate.
  • Use Case: You need to add a new, non-nullable column to a large users table in PostgreSQL without locking the table or causing downtime. This Skill provides the exact SQL and strategy to achieve this safely.

Quick Start

Use the database-migrations skill to learn how to add a new column to a PostgreSQL table safely.

Frequently Asked Questions about database-migrations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a non-nullable column to a large PostgreSQL table without locking it?

To add a non-nullable column without locking a PostgreSQL table, you must use a multi-step zero-downtime migration strategy. This involves adding the column as nullable, backfilling the data, and finally enforcing the constraint after deployment.

What is a zero-downtime database migration?

A zero-downtime database migration is a schema evolution technique that applies changes without interrupting service. It decouples schema updates from application deployments, often using concurrent index creation and backfilling strategies to prevent table locks.

Does this database migration guidance work with Prisma and Django ORM tooling?

Yes, the guidance covers tooling integration patterns for Prisma, Drizzle, Django, and golang-migrate. It provides best practices for safe schema changes and data migrations specific to these ORM environments.

What's the best way to backfill data during a schema change?

The best way to backfill data during a schema change is to batch the updates in small chunks. This approach minimizes table locks and transaction overhead, ensuring the data migration remains safe and reversible.

How does concurrent index creation prevent downtime during schema updates?

Concurrent index creation prevents downtime by allowing the database to continue serving read and write operations while the index builds. This avoids the exclusive table lock required by standard index creation.

When should I not use a direct schema migration on a production database?

You should avoid direct schema migrations when changes involve large tables or non-nullable constraints that cause table locks. Instead, use reversible patterns and incremental deployments to prevent service interruptions.