database-migration-patterns

Apply expand-then-contract migration patterns to PostgreSQL databases with Alembic.

2|Updated Jan 2, 2026
One-click install
npx skills add https://github.com/mindmorass/reflex --skill database-migration-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-migration-patterns
Source: https://github.com/mindmorass/reflex/tree/main/plugins/reflex/skills/database-migration-patterns
Command: npx skills add https://github.com/mindmorass/reflex --skill database-migration-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Eliminate downtime during schema changes by applying safe migration patterns and structured workflows.

Core Features & Use Cases

  • Zero-downtime migration patterns (Expand-Contract, Safe column rename, NOT NULL handling in stages)
  • Safe indexing and backfill strategies to minimize locking and downtime
  • Data migration guidance with separate data migrations and rollback planning

Quick Start

Start by adopting a small, safe migration in a staging environment, then mirror the approach to production using the provided templates and guidelines.

Frequently Asked Questions about database-migration-patterns

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

FAQPage Schema
How do I perform zero-downtime schema changes on a PostgreSQL database?

Zero-downtime schema changes use the expand-contract pattern: add new schema elements without removing old ones, migrate data in stages, then clean up deprecated columns. This approach keeps the database available throughout by separating reads from writes and avoiding long-running locks.

What's the safest way to rename a column in PostgreSQL without downtime?

Safe column rename uses the expand-contract strategy: create a new column, backfill data, update application code to write to both columns, verify correctness, then drop the old column. Alembic migrations enforce this sequence with versioned scripts and rollback plans.

How do I add a NOT NULL constraint to an existing PostgreSQL column without locking the table?

Add NOT NULL in stages: first make the column NOT NULL at the application level by validating before insert, then add a CHECK constraint without validation, backfill any nulls, and finally enforce the database constraint. This avoids table locks during the migration.

Can I create indexes on large PostgreSQL tables without causing downtime?

Create indexes safely using CONCURRENTLY in PostgreSQL, which builds the index without blocking writes. Alembic templates guide this approach alongside backfill strategies that minimize locking and maintain availability during index creation on production data.

What precautions should I take when migrating data between PostgreSQL columns?

Data migrations require separate Alembic scripts, staged backfills to avoid locks, validation checks to confirm correctness, and tested rollback plans. Split large migrations into smaller batches and run them during low-traffic windows to minimize impact.

Why should I use versioned migrations instead of manual schema changes in PostgreSQL?

Versioned migrations with Alembic track every schema change, enable reproducible deployments across environments, enforce best practices like expand-contract and safe indexing, and provide rollback capabilities if a production change fails or causes issues.