Specx sqlalchemy migrations

From maksimzayats/specx · View interactive version

Specx sqlalchemy migrations is an AI agent skill from the GitHub repository maksimzayats/specx. Add or repair Alembic migrations for specx SQLAlchemy services. Use when adding SQLAlchemy models or repositories, replacing metadata.create_all schema bootstraps, creating async Alembic env.py, adding migration Makefile targets, generating initial revisions, or testing migration drift.

How to use this skill

Skill file

specx SQLAlchemy Migrations

Use this skill whenever a specx project has SQLAlchemy models or persistence

adapters. Read references/alembic.md before editing migration files.

Workflow

  1. Add alembic>=1.18.5 as a runtime dependency when SQLAlchemy adapters

exist, together with SQLAlchemy's asyncio extra and the selected driver.

  1. Add alembic.ini, migrations/env.py, migrations/script.py.mako, and

migrations/versions/.

  1. Use Alembic's async pattern for async SQLAlchemy engines.
  2. Put app-wide SQLAlchemy settings/session factory under top-level

infrastructure/sqlalchemy/.

  1. Keep scope-owned ORM models and repositories under

core/<scope>/infrastructure/sqlalchemy/.

  1. Add a project-local SQLAlchemy declarative base under

src/<package>/foundation/sqlalchemy_model.py; do not use shared packaged

metadata for generated services.

  1. Put reusable model discovery under top-level

infrastructure/sqlalchemy/model_discovery.py. Use that same function from

migrations/env.py and its guardrail test before assigning

target_metadata; do not duplicate discovery or maintain hard-coded model

module names.

  1. Set target_metadata to the project-local BaseSQLAlchemyModel.metadata.
  2. Generate or hand-review an initial migration for current models.
  3. Add make migrate and make makemigrations.
  4. Add tests that run alembic upgrade head against an isolated database,

check for pending autogenerate changes, and prove every core SQLAlchemy

model file is included by the exact discovery function Alembic uses. Use

the production database family when dialect behavior matters.

Guardrails

drop_all from src/.

operational command before app startup.

migration helpers.

must include every core/*/infrastructure/sqlalchemy/models/*.py file.

add a new corrective revision.

savepoint-based SQLite test harness spanning Python versions, use

SQLAlchemy's connect and begin event-hook recipe.

Code Style

Use blank lines as logical separators in all code. Keep related statements

together, but separate independent setup, action, assertion, response, branch,

and transformation groups so long blocks stay readable.

References

initial migration, and migration tests.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.