safe-migrations

Guide Django PostgreSQL migrations with expand-contract and chunked backfills.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/arsen-ask-lx/.claude_file_4all --skill safe-migrations-arsen-ask-lx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-migrations
Source: https://github.com/arsen-ask-lx/.claude_file_4all/tree/main/skills/safe-migrations
Command: npx skills add https://github.com/arsen-ask-lx/.claude_file_4all --skill safe-migrations-arsen-ask-lx

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Safe Django migrations for PostgreSQL in production, enabling zero-downtime deployments by using an Expand-and-Contract pattern, careful lock management, and chunked data migrations for large tables.

Core Features & Use Cases

  • Expand-and-Contract pattern to split deployment into pre- and post-migration phases
  • Safe lock management and PostgreSQL blocking considerations (lock_timeout, concurrently)
  • Data migrations with chunked backfills and idempotence
  • Safe column rename and removal strategies with SeparateDatabaseAndState
  • Concurrent index/constraint operations and two-phase constraint validation
  • Squashing migrations guidance and deployment order

Quick Start

Begin by adding a nullable column, backfill data in small batches, then finalize by enforcing NOT NULL in a separate migration.

Frequently Asked Questions about safe-migrations

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

FAQPage Schema
How do I run zero-downtime PostgreSQL migrations in Django without table locks?

Zero-downtime PostgreSQL migrations in Django use the Expand-and-Contract pattern to split schema changes into pre- and post-migration phases, avoiding long table locks by adding nullable columns first and finalizing constraints later.

What is the best way to backfill data in large PostgreSQL tables during a Django migration?

Backfilling data in large PostgreSQL tables during Django migrations is done in small chunks or batches, ensuring idempotence to prevent locking issues and allowing safe processing without blocking concurrent database operations.

How do I safely rename or remove a column in Django without downtime?

Safe column renames and removals in Django use SeparateDatabaseAndState to decouple schema state from database operations, allowing multi-phase deployments that prevent downtime and lock conflicts on large PostgreSQL tables.

Can I create indexes concurrently in PostgreSQL using Django migrations?

Concurrent index creation in PostgreSQL during Django migrations is supported by using specific lock management patterns and two-phase constraint validation, ensuring indexes are built without blocking writes or causing deployment downtime.

How does the Expand-and-Contract pattern work for Django schema changes?

The Expand-and-Contract pattern for Django schema changes splits deployment into pre- and post-migration phases: first expanding by adding new nullable columns or tables, then contracting by removing old columns after application code fully transitions.

What PostgreSQL lock management settings are needed for safe Django migrations?

Safe Django migrations on PostgreSQL require lock management settings like lock_timeout and concurrent index operations to prevent blocking transactions, ensuring long-running schema changes do not lock out concurrent database access.