Skip to content
Back to skills

Sqlalchemy Alembic Expert Best Practices Code Review

ASecurity

SQLAlchemy ORM and Alembic migration best practices for building safe, performant database schemas. This skill should be used when writing, reviewing, or refactoring SQLAlchemy models, Alembic migrations, or database query patterns. Triggers on tasks involving SQLAlchemy ORM, Alembic migrations, database schema changes, or query optimization.

  • 8 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added February 11, 2026
databasesgosqlrefactoringcode-reviewdatabaseperformance

Security analysis

A100/100

Pro scans all 9 files and shows the line behind each finding

Scanned February 12, 2026

npx -y skills add wispbit-ai/skills --skill sqlalchemy-alembic-expert-best-practices-code-review --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sqlalchemy Alembic Expert Best Practices Code Review?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sqlalchemy Alembic Expert Best Practices Code Review
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wispbit-ai-sqlalchemy-alembic-expert-best-practices-code-revi/badge)](https://www.skillsdirectory.com/skills/wispbit-ai-sqlalchemy-alembic-expert-best-practices-code-revi)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sqlalchemy-alembic-expert-best-practices-code-review
description: SQLAlchemy ORM and Alembic migration best practices for building safe, performant database schemas. This skill should be used when writing, reviewing, or refactoring SQLAlchemy models, Alembic migrations, or database query patterns. Triggers on tasks involving SQLAlchemy ORM, Alembic migrations, database schema changes, or query optimization.
license: MIT
metadata:
  author: wispbit
  version: "1.0.0"
---

# SQLAlchemy & Alembic Expert Best Practices

Simple, pragmatic, opinionated. Only what matters for writing production-grade SQLAlchemy and Alembic code.

## When to Apply

Reference these guidelines when:
- Writing Alembic migrations for schema changes
- Creating or modifying SQLAlchemy models
- Adding indexes, constraints, or foreign keys via Alembic
- Reviewing database migration code for safety
- Refactoring existing database schemas
- Optimizing query patterns or database performance

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Index Management | CRITICAL-HIGH | `only-concurrent-indexes`, `verify-query-patterns-are-indexed` |
| 2 | Constraint Safety | HIGH | `unique-constraint`, `split-foreign-key`, `change-column-type` |
| 3 | Optimization | MEDIUM | `split-check-constraint`, `limit-non-unique-index` |
| 4 | Index Efficiency | LOW | `ensure-index-not-covered` |

## Quick Reference

- `only-concurrent-indexes` - Always use `postgresql_concurrently=True` with autocommit blocks for index operations
- `verify-query-patterns-are-indexed` - Ensure SQLAlchemy queries have appropriate indexes defined
- `unique-constraint` - Split unique constraint creation into concurrent index + constraint steps
- `split-foreign-key` - Add foreign keys with `NOT VALID` first, then validate separately
- `change-column-type` - Use multi-step approach for column type changes to avoid table locks
- `split-check-constraint` - Add check constraints with `NOT VALID` first, then validate separately
- `limit-non-unique-index` - Limit non-unique indexes to maximum three columns for efficiency
- `ensure-index-not-covered` - Prevent redundant indexes that are already covered by composite indexes

## How to Use

Read individual rule files for detailed explanations and code examples:

```
rules/only-concurrent-indexes.md
rules/verify-query-patterns-are-indexed.md
rules/unique-constraint.md
rules/split-foreign-key.md
rules/change-column-type.md
rules/split-check-constraint.md
rules/limit-non-unique-index.md
rules/ensure-index-not-covered.md
```

Each rule file contains:
- Brief explanation of why it matters
- Impact level and description
- Incorrect SQLAlchemy/Alembic example with explanation
- Correct implementation with best practices
- Additional context for safe migrations

Files in this skill

  • SKILL.md2.8 KB
  • rules/change-column-type.md1.6 KB
  • rules/ensure-index-not-covered.md1.2 KB
  • rules/limit-non-unique-index.md911 B
  • rules/only-concurrent-indexes.md980 B
  • rules/split-check-constraint.md1 KB
  • rules/split-foreign-key.md1.2 KB
  • rules/unique-constraint.md1.1 KB
  • rules/verify-query-patterns-are-indexed.md1.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…