db-alembic-schema
Write or modify SQLAlchemy ORM models in apps/api/app/infrastructure/ and execute safe Alembic migrations. Use for database model, relation, index, enum changes, or schema-to-domain-layer sync.
- License 许可
- MIT
- 最近更新
- 2026-10-12
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- db-alembic-schema
- description
- Write or modify SQLAlchemy ORM models in apps/api/app/infrastructure/ and execute safe Alembic migrations. Use for database model, relation, index, enum changes, or schema-to-domain-layer sync.
02 资源文件 3
- 参考文档agents/openai.yaml306 B
- 参考文档references/context.md2.9 KB
- 参考文档templates/checklist.md900 B
03 SKILL.md 正文
Skill: DB Alembic Schema
Context (Required)
- Folder scope + code samples:
references/context.md - Execution checklist:
templates/checklist.md
Apply schema changes minimally and safely using SQLAlchemy ORM models and Alembic migrations.
Naming Conventions
Tables & Columns
| Category | Table Prefix | Example |
|---|---|---|
| Master / reference data | master_ |
master_service_types |
| Transaction / business data | business_ |
business_shipments |
| Membership data | member_ |
member_profiles |
| User / auth data | (no prefix) | users, auth_sessions |
| System config data | (no prefix) | configurations |
- Table names:
snake_caseplural (e.g.,users,auth_sessions) - Column names:
snake_case(e.g.,created_at,is_active)
Boolean Fields — prefix is or has
Enum Values — SCREAMING_SNAKE_CASE
If a field has a fixed set of values, declare a Python StrEnum in apps/api/app/domain/models.py as the source of truth. Use Enum(PythonEnum) in the SQLAlchemy column.
# domain/models.py (source of truth)
class UserStatus(StrEnum):
ACTIVE = "ACTIVE"
SUSPENDED = "SUSPENDED"
# infrastructure/database.py — use Enum(StrEnum)
status: Mapped[UserStatus] = mapped_column(Enum(UserStatus, name="UserStatus"), default=UserStatus.ACTIVE, nullable=False)
Required Standard Fields
id: Mapped[str] = mapped_column(Uuid(as_uuid=False), primary_key=True)
created_at: Mapped[datetime] = mapped_column("created_at", DateTime(timezone=False), default=utc_now, nullable=False)
updated_at: Mapped[datetime] = mapped_column("updated_at", DateTime(timezone=False), default=utc_now, onupdate=utc_now, nullable=False)
deleted_at: Mapped[datetime | None] = mapped_column("deleted_at", DateTime(timezone=False), nullable=True)
Workflow
- Read
apps/api/app/infrastructure/database.pyto understand existing ORM records. - Read
apps/api/app/domain/models.pyto ensure entities and StrEnums are in sync. - Identify breaking vs non-breaking changes.
- Write minimal diff to the ORM record class.
- Run:
uv run alembic revision --autogenerate -m "<description>" - Review the generated migration file in
alembic/versions/. - Run:
uv run alembic upgrade head - If a new entity/field is added, sync
domain/models.pyanddomain/repositories.py.
Prohibitions
- NEVER rename a table, column, or enum without a clear requirement.
- NEVER drop an existing column or relation without documenting the migration impact.
- NEVER leave placeholders or names that violate the prefix convention.
- NEVER edit files outside the ORM/migration scope unless the task requires it.
- NEVER run
alembic downgradeon a shared database without explicit confirmation.
Pre-Completion Checklist
- [ ] Table naming follows the category prefix
- [ ] Table name is
snake_caseplural - [ ] Column names are
snake_case - [ ] Boolean fields prefixed
isorhas - [ ] Enum values in SCREAMING_SNAKE_CASE
- [ ] Standard fields present: id, created_at, updated_at
- [ ]
StrEnumdeclared indomain/models.py(if new enum) - [ ] `uv run alembic revision --autogenerate -m "<desc>" run
- [ ] Migration file reviewed
- [ ]
uv run alembic upgrade headpasses - [ ]
uv run mypy apppasses - [ ] Every file ends with a newline (EOF)
04 同仓库更多 Skills
web-slicing
Convert screenshot/Figma designs into pixel-perfect frontend UI with reusable components. Use when the task focuses on visual and layout implementation.
web-seo-geo-friendly
Optimize public Next.js App Router pages for SEO and GEO (Generative Engine Optimization). Use when the user explicitly requests SEO/GEO optimization on public pages.
web-code-review
Review frontend code with a firm senior-lead standard, focusing on bugs, regressions, architecture risks, and test gaps in apps/web and the shared contracts the frontend depends on.
web-bugfix
Fix frontend bugs with minimum-touch changes, keep other surfaces stable, and sync schema, types, hooks, constants, tests, and related docs when impacted.
web-api-integrated
Integrate API endpoints into the frontend with Zod schemas, response types, constants, and react-query hooks. Use when implementing endpoints from an API contract, Postman, or Swagger.
skill-creator
Create a new skill from scratch with full structure — SKILL.md, references, templates, openai.yaml, Claude wrapper, and registration in manifest + AGENTS.md + CLAUDE.md.