Sqlalchemy Alembic Expert Best Practices Code Review

wispbit-ai/skills/skills/sqlalchemy-alembic-expert-best-practices-code-review

作者 wispbit-ai8b2c7d0ceca0MIT8 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7个月前更新

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.

AI 生成的概览

用于编写和审查安全、高效的 SQLAlchemy 模型与 Alembic 迁移的准则。

功能
该技能为 SQLAlchemy ORM 模型和 Alembic 数据库迁移提供有明确倾向的最佳实践规则。内容涵盖索引管理、约束安全性和优化,每个规则文件都包含说明、影响级别以及错误与正确代码示例。它是一组参考文档,而不是生成文件的工具。
适用场景
适用于编写、审查或重构 SQLAlchemy 模型、Alembic 迁移或数据库查询模式时。在添加索引、约束或外键,或优化查询性能时也同样适用。
运行要求
无需脚本或运行时依赖,仅为说明和规则文档。

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.mdrules/verify-query-patterns-are-indexed.mdrules/unique-constraint.mdrules/split-foreign-key.mdrules/change-column-type.mdrules/split-check-constraint.mdrules/limit-non-unique-index.mdrules/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

来源与署名

来源:wispbit-ai/skills位于skills/sqlalchemy-alembic-expert-best-practices-code-review提交8b2c7d0

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架