skillfed

django-migration-psql

This skill audits Django migration files against PostgreSQL safety rules, catching common mistakes like bundling index creation with model definitions, mixing indexes across tables, and mishandling partitioned table indexes. It enforces separation of concerns—structural changes in one migration, performance indexes in another—and provides the two-step pattern required for partitioned tables to ensure indexes apply to all existing partitions without locking production data.

django-migration-psql reviews Django migrations for PostgreSQL best practices to prevent production table locks and data issues.

AI-generated summary based on this skill's SKILL.md

14,491 2,285 Apache-2.0 updated by prowler-cloud

Install

prowler-cloud/prowler/django-migration-psql · repository language: Python

git clone https://github.com/prowler-cloud/prowler
cp -r prowler/skills/django-migration-psql ~/.claude/skills/django-migration-psql
npx skillfed install prowler-cloud/prowler/django-migration-psql

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

What does django-migration-psql help with?

django-migration-psql audits Django migration files against PostgreSQL safety rules, catching common mistakes like bundling index creation with model definitions, mixing indexes across tables, and mishandling partitioned table indexes. It enforces separation of concerns—structural changes in one migration, performance indexes in another—and provides the two-step pattern required for partitioned tables to ensure indexes apply to all existing partitions without locking production data.

How should I split django migrations for PostgreSQL?

django-migration-psql enforces splitting auto-generated migrations into separate concerns: keep structural changes (CreateModel, AddField) in one migration and performance indexes in another. For partitioned tables, use a two-step pattern: first create the index on the parent table, then apply it to existing partitions. This separation prevents locking production data and ensures indexes apply correctly across all partitions.

How do I create index concurrently in django migrations?

django-migration-psql supports concurrent index creation on partitioned tables without locking production. Use the two-step pattern: create the index on the parent table in one migration with `atomic=False`, then apply it to existing partitions in a follow-up migration. This approach prevents blocking production queries while ensuring all partitions receive the index.

What does django migration review checklist include?

django-migration-psql's review checklist validates that migrations follow PostgreSQL best practices: indexes are separated from model definitions, partitioned table indexes use the two-step pattern, data backfills use batched Celery tasks, migrations avoid unnecessary locking, and structural changes are isolated from performance tuning. It also checks for proper use of `atomic=False` and constraint handling.

Can django-migration-psql help with data backfill migrations?

Yes. django-migration-psql supports implementing batched data backfills safely using Celery tasks within migrations. Instead of loading all data into memory at once, use RunPython with batched queries and Celery task scheduling to backfill large tables incrementally, reducing memory overhead and production impact.

How does django-migration-psql handle partitioned table indexes?

django-migration-psql enforces a two-step pattern for partitioned table indexes: first create the index on the parent table without locking production, then apply it to existing partitions in a separate migration. This ensures indexes apply to all partitions correctly and prevents the common mistake of creating indexes that miss existing partition data.

SKILL.md

rendered from the published skill — quoted content, verbatim

When to use

  • Creating a new Django migration
  • Running makemigrations or pgmakemigrations
  • Reviewing a PR that adds or modifies migrations
  • Adding indexes, constraints, or models to the database

Why this matters

A bad migration can lock a production table for minutes, block all reads/writes, or

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 1 file
skills/django-migration-psql/SKILL.md

Related skills

Tags

schema-design database-locking concurrent-indexing data-migration partition-strategy production-safety transaction-management performance-optimization rollback-safety