# Review Safer Alembic Migrations

Alembic autogenerate can create migrations that lose data or lock tables. This skill gives practical PostgreSQL patterns for safer schema changes, reviews, testing, and production rollout.

## Install

```bash
npx skillstore add cjharmath/py-alembic-patterns
```

## Metadata

- Status: approved
- Slug: cjharmath-py-alembic-patterns
- Skillstore revision: r1
- Version status: missing
- Tree hash: 1c9d778e9ad8d29d093db979252c1f85c8283d106b8ff5d46fc6a294720d9bf2
- Author: CJHarmath
- GitHub username: CJHarmath
- License: MIT
- Repository: https://github.com/CJHarmath/claude-agents-skills/tree/main/skills/py-alembic-patterns
- Ref: 02f077c174c5335e2f5d02ca15e77b70d9543e58
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/cjharmath-py-alembic-patterns
- Manifest: https://skillstore.pages.dev/api/skills/cjharmath-py-alembic-patterns/manifest

## Capabilities

- Explains common Alembic commands for revision generation, upgrades, downgrades, history, and branch heads.
- Shows how to review autogenerated migrations for unsafe drop-and-add rename patterns.
- Provides examples for non-nullable columns, data migrations, enum changes, indexes, and foreign keys.
- Covers large-table concerns such as concurrent indexes, batching, and statement timeouts.
- Includes a migration review checklist for downgrade coverage, naming, constraints, and testing.
- Shows pytest-style migration upgrade and downgrade test patterns.

## Use Cases

- Review an autogenerated migration: Check an Alembic autogenerate result for data-loss patterns, missing names, unsafe constraints, and incomplete downgrade logic.
- Plan a production schema change: Design safer PostgreSQL steps for large tables, non-null columns, indexes, enum changes, and data backfills.
- Add migration tests to a service: Create test coverage that upgrades, downgrades, and upgrades again to catch broken migration history early.

## Prompt Templates

### Review my migration

```
Review this Alembic migration for PostgreSQL safety. Check for data loss, missing downgrade steps, unsafe defaults, and lock risks. Explain the changes I should make.
```

### Create a safe migration plan

```
Help me design an Alembic migration for this schema change. Use PostgreSQL-safe steps, include downgrade behavior, and call out testing requirements.
```

### Fix autogenerated output

```
This Alembic autogenerate output looks risky. Rewrite the migration approach to preserve data, use explicit names, and handle existing rows safely.
```

### Assess production rollout risk

```
Evaluate this migration for production rollout. Consider locks, large-table behavior, concurrent indexes, enum changes, transaction settings, backups, and rollback options.
```

## Limitations

- It provides guidance only and does not inspect a live database by itself.
- Examples assume PostgreSQL and may need changes for other database engines.
- It cannot verify production data volume, locks, or runtime permissions without project context.
- It does not replace a human review before applying migrations to production.

## Best Practices

- Review every autogenerated migration before it reaches production.
- Use explicit names for indexes, foreign keys, constraints, and enum types.
- Test upgrade, downgrade, and upgrade again with realistic data where possible.

## Anti Patterns

- Treating a column rename as drop and add without preserving existing data.
- Adding a non-nullable column to a populated table without a backfill plan.
- Applying production migrations without preview, backup, rollback, and lock review.

## Security Audit

- Audited at: 2026-07-05T06:16:19.61\+00:00
- Summary: All static findings were false positives caused by Markdown code fences, inline-code formatting, and static Alembic or PostgreSQL examples. I found no prompt injection, hidden execution path, credential exfiltration, network abuse, or system reconnaissance intent in SKILL.md.

## Stats

- Views: 229
- Downloads: 9
- Favorites: 0
- Popularity score: 0
