com um clique
stk-migrate
// Generate and review an Alembic database migration for stk. Use when adding or changing models, creating migrations, or managing database schema changes.
// Generate and review an Alembic database migration for stk. Use when adding or changing models, creating migrations, or managing database schema changes.
| name | stk-migrate |
| description | Generate and review an Alembic database migration for stk. Use when adding or changing models, creating migrations, or managing database schema changes. |
| argument-hint | [description] |
Current revision:
!cd /Users/level09/projects/stk && uv run quart db current 2>&1 | tail -5
Recent migrations:
!ls -1t alembic/versions/*.py 2>/dev/null | head -10
Models with tables:
!grep -rn "__tablename__" stk/*/models.py 2>/dev/null
Generate the migration:
uv run quart db revision -m "$ARGUMENTS"
Review the generated file in alembic/versions/. Check:
downgrade() correctly reverses upgrade()For SQLite compatibility, verify batch mode is used. The env.py enables render_as_batch automatically for SQLite, but if writing manual SQL, wrap ALTER TABLE operations in with op.batch_alter_table().
If the migration needs manual edits (data migrations, complex constraints, multi-step operations):
op.execute() for raw SQL when neededTest the migration:
uv run quart db upgrade # apply
uv run quart db downgrade -1 # rollback
uv run quart db upgrade # re-apply to confirm idempotency
Run checks:
uv run python checks.py
Models use @dataclasses.dataclass and inherit from Base (stk.extensions). Key patterns:
id = Column(Integer, primary_key=True)created_at = Column(DateTime, default=datetime.now, nullable=False)Column(Integer, ForeignKey("table.id")) or Column(String(64), ForeignKey("table.field", ondelete="CASCADE"))Column(JSON, nullable=True)unique=True on column or UniqueConstraint(...) in __table_args__Add a column:
op.add_column("users", sa.Column("bio", sa.Text(), nullable=True))
Add an index:
op.create_index("ix_products_name", "products", ["name"])
Data migration (backfill):
from alembic import op
from sqlalchemy import text
def upgrade():
op.add_column("users", sa.Column("display_name", sa.String(255)))
op.execute(text("UPDATE users SET display_name = name WHERE display_name IS NULL"))
Rename with SQLite (batch mode):
with op.batch_alter_table("users") as batch_op:
batch_op.alter_column("old_name", new_column_name="new_name")
Add a composite unique constraint:
op.create_unique_constraint("uq_oauth_provider_user", "oauth", ["provider", "provider_user_id"])
Generate async CRUD API endpoints for an existing stk model. Use when adding API routes, REST endpoints, or CRUD operations to an stk blueprint.
Scaffold a new stk blueprint with models, views, templates, and Alembic migration. Use when creating a new feature module, adding a new section to the app, or scaffolding a blueprint.
Background knowledge for stk async Quart framework development. Auto-loads when working on stk-based code: models, views, templates, database queries, auth patterns, Vue frontend. Provides conventions, patterns, and gotchas so Claude writes correct async Quart code instead of Flask patterns.