- Initialize Alembic with alembic init alembic - Configure alembic.ini to use DATABASE_URL from environment - Configure alembic/env.py to import Base and models metadata - Generate initial migration: c92fc544a483_initial_schema - Migration creates all 4 tables: users, api_keys, api_tokens, usage_stats - Migration includes all indexes, constraints, and foreign keys - Test upgrade/downgrade cycle works correctly Alembic commands: - alembic upgrade head - alembic downgrade -1 - alembic revision --autogenerate -m 'message' Tests: 13 migration tests pass
29 lines
704 B
Mako
29 lines
704 B
Mako
"""${message}
|
|
|
|
Revision ID: ${up_revision}
|
|
Revises: ${down_revision | comma,n}
|
|
Create Date: ${create_date}
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
${imports if imports else ""}
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = ${repr(up_revision)}
|
|
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
|
|
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
${upgrades if upgrades else "pass"}
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
${downgrades if downgrades else "pass"}
|
|
|