# Manage Alembic Database Migrations

Database schema changes can break apps or lose data. This skill guides Alembic setup, revision generation, upgrades, rollbacks, and review checks.

## Install

```bash
npx skillstore add awais68/db-migration
```

## Metadata

- - Status: approved
- - Slug: awais68-db-migration
- - Version: 1.0.0
- - Author: Awais68
- - GitHub username: Awais68
- - License: MIT
- - Repository: https://github.com/Awais68/hackathon-2-phase-ii-full-stack-web-app/tree/main/.claude/skills/db-migration
- - Ref: main
- - Supported tools: Claude, Codex, Claude Code
- - Risk level: medium
- - Risk factors: scripts, env\_access, external\_commands
- - Quality score: 50
- - Quality tier: warning
- - Public page: https://skillstore.pages.dev/skills/awais68-db-migration
- - Manifest: https://skillstore.pages.dev/api/skills/awais68-db-migration/manifest

## Capabilities

- Explains how to initialize Alembic for a project.
- Shows how to configure Alembic for SQLModel metadata.
- Provides commands for generating, applying, and rolling back revisions.
- Gives examples for table, column, enum, and data migrations.
- Lists review checks for indexes, foreign keys, defaults, and downgrade paths.
- Suggests a migration directory structure for FastAPI projects.

## Use Cases

- Set up migration tooling: Initialize Alembic and configure metadata for a new SQLModel application.
- Review schema changes before release: Check autogenerated revisions for indexes, constraints, defaults, and rollback safety.
- Plan safe data migrations: Design batch updates and downgrade behavior for existing production data.

## Prompt Templates

### Initialize Alembic

```
Set up Alembic for my FastAPI and SQLModel project. Explain the files I need to create and the configuration I should review.
```

### Generate a Revision

```
Help me generate an Alembic migration for recent SQLModel changes. Include the review checklist before I apply it.
```

### Review a Migration Plan

```
Review this migration plan for data loss, missing indexes, foreign key ordering, downgrade behavior, and database dialect risks.
```

### Design a Data Migration

```
Design a safe Alembic data migration for a large table. Include batching strategy, rollback approach, testing steps, and deployment cautions.
```

## Limitations

- It does not connect to a database or verify live schema state by itself.
- It does not replace backups, staging tests, or production change approvals.
- It focuses on Alembic, SQLModel, SQLAlchemy, and FastAPI workflows.
- Generated examples must be adapted to each database dialect and project model.

## Best Practices

- Run migrations against a disposable test database before using shared environments.
- Review autogenerated revisions for destructive operations and missing constraints.
- Back up production data and document rollback limits before applying migrations.

## Anti Patterns

- Applying autogenerated migrations without reading the generated operations.
- Running downgrade commands against production without a recovery plan.
- Embedding real database passwords in migration configuration files.

## Security Audit

- - Safe to publish: true
- - Audited at: 2026-06-28T12:12:52.117\+00:00
- - Summary: Static analysis reported many weak cryptography and command execution patterns, but manual review found no malware, prompt injection, network access, or data exfiltration. Most high-severity cryptography findings are false positives caused by Markdown, migration identifiers, and validation regex. The remaining risk is operational: the skill teaches database commands and SQL migrations that can modify or remove data if used without review.

## Stats

- - Views: 151
- - Downloads: 7
- - Favorites: 0
- - Popularity score: 0
