mcpField
S
sqlalchemy-alembic-expert-best-practices-code-review

sqlalchemy-alembic-expert-best-practices-code-review

github.com/midudevData & databases7.0k63 installsUpdated 1w ago
Repository

About sqlalchemy-alembic-expert-best-practices-code-review

A set of practical guidelines for SQLAlchemy and Alembic development and code review. It is intended for developers working on schema changes, migrations, and query performance, with emphasis on safe index and constraint operations.

Key features

  1. 01Guidance for safe Alembic migrations
  2. 02Concurrent index operation practices
  3. 03Staged foreign key and check constraints
  4. 04Safer column type changes
  5. 05Query indexing and redundant index checks

Use cases

  1. 01Review a schema migration for locking risks
  2. 02Add an index with reduced disruption
  3. 03Change a column type in stages
  4. 04Check query patterns against defined indexes

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/midudev/autoskills --skill sqlalchemy-alembic-expert-best-practices-code-review

After installing, type/sqlalchemy-alembic-expert-best-practices-code-reviewin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

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

Details

From the project README

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

PriorityCategoryImpactPrefix
1Index ManagementCRITICAL-HIGHonly-concurrent-indexes, verify-query-patterns-are-indexed
2Constraint SafetyHIGHunique-constraint, split-foreign-key, change-column-type
3OptimizationMEDIUMsplit-check-constraint, limit-non-unique-index
4Index EfficiencyLOWensure-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

Comments

Markdown supported