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 從公開儲存庫中收錄這些內容。

檢舉或申請下架