---
name: "postgres-schema-diff-migra"
description: "Generate safe, automated DDL migration scripts by diffing PostgreSQL database states."
metadata:
  author: "djrobstep"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "diff postgres schemas"
  - "generate ddl migration migra"
  - "declarative postgres migrations"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Migra PostgreSQL Schema Diff & Declarative Migrations

Compares source and target PostgreSQL databases using Migra: generating idempotent ALTER TABLE statements, identifying dropped constraints, reordering dependent foreign keys, and preventing destructive drops.

## When to Invoke
Invoke this skill whenever you need to:
- diff postgres schemas
- generate ddl migration migra
- declarative postgres migrations

## Execution SOP & Rules
1. Install migra using pip install migra[pg] or run via Docker container.
2. Run migra --unsafe postgresql:///dev_db postgresql:///prod_db to view required DDL transformations.
3. Inspect generated DDL carefully for table locks or column rewrites before executing in production.
4. Combine with sqlfluff or dry-run transaction blocks to guarantee zero-downtime schema evolution.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
