fix: regenerate Alembic migration with complete schema
Previous migrations were empty (just 'pass'). Regenerated a single migration that includes all models: Admin, Exchange, Participant, MagicToken, and RateLimit tables with proper indexes and constraints. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
"""Initial schema with all models
|
||||
|
||||
Revision ID: ef9ca3b9cc26
|
||||
Revises:
|
||||
Create Date: 2025-12-22 17:48:23.273368
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "ef9ca3b9cc26"
|
||||
down_revision: str | Sequence[str] | None = None
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"admin",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("email", sa.String(length=255), nullable=False),
|
||||
sa.Column("password_hash", sa.String(length=255), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_admin_email"), "admin", ["email"], unique=True)
|
||||
op.create_table(
|
||||
"exchange",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("slug", sa.String(length=12), nullable=False),
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("budget", sa.String(length=100), nullable=False),
|
||||
sa.Column("max_participants", sa.Integer(), nullable=False),
|
||||
sa.Column("registration_close_date", sa.DateTime(), nullable=False),
|
||||
sa.Column("exchange_date", sa.DateTime(), nullable=False),
|
||||
sa.Column("timezone", sa.String(length=50), nullable=False),
|
||||
sa.Column("state", sa.String(length=20), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("completed_at", sa.DateTime(), nullable=True),
|
||||
sa.CheckConstraint("max_participants >= 3", name="min_participants_check"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_exchange_completed_at"), "exchange", ["completed_at"], unique=False
|
||||
)
|
||||
op.create_index(op.f("ix_exchange_slug"), "exchange", ["slug"], unique=True)
|
||||
op.create_index(op.f("ix_exchange_state"), "exchange", ["state"], unique=False)
|
||||
op.create_table(
|
||||
"rate_limit",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("key", sa.String(length=255), nullable=False),
|
||||
sa.Column("attempts", sa.Integer(), nullable=False),
|
||||
sa.Column("window_start", sa.DateTime(), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_rate_limit_key"), "rate_limit", ["key"], unique=True)
|
||||
op.create_table(
|
||||
"participant",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("exchange_id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(length=255), nullable=False),
|
||||
sa.Column("email", sa.String(length=255), nullable=False),
|
||||
sa.Column("gift_ideas", sa.Text(), nullable=True),
|
||||
sa.Column("reminder_enabled", sa.Boolean(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("withdrawn_at", sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(["exchange_id"], ["exchange.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index("idx_participant_email", "participant", ["email"], unique=False)
|
||||
op.create_index(
|
||||
"idx_participant_exchange_email",
|
||||
"participant",
|
||||
["exchange_id", "email"],
|
||||
unique=True,
|
||||
)
|
||||
op.create_index(
|
||||
"idx_participant_exchange_id", "participant", ["exchange_id"], unique=False
|
||||
)
|
||||
op.create_table(
|
||||
"magic_token",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("token_hash", sa.String(length=255), nullable=False),
|
||||
sa.Column("token_type", sa.String(length=20), nullable=False),
|
||||
sa.Column("email", sa.String(length=255), nullable=False),
|
||||
sa.Column("participant_id", sa.Integer(), nullable=True),
|
||||
sa.Column("exchange_id", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("used_at", sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(["exchange_id"], ["exchange.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(
|
||||
["participant_id"], ["participant.id"], ondelete="CASCADE"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("token_hash"),
|
||||
)
|
||||
op.create_index(
|
||||
"idx_magic_token_expires_at", "magic_token", ["expires_at"], unique=False
|
||||
)
|
||||
op.create_index("idx_magic_token_hash", "magic_token", ["token_hash"], unique=True)
|
||||
op.create_index(
|
||||
"idx_magic_token_type_email",
|
||||
"magic_token",
|
||||
["token_type", "email"],
|
||||
unique=False,
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index("idx_magic_token_type_email", table_name="magic_token")
|
||||
op.drop_index("idx_magic_token_hash", table_name="magic_token")
|
||||
op.drop_index("idx_magic_token_expires_at", table_name="magic_token")
|
||||
op.drop_table("magic_token")
|
||||
op.drop_index("idx_participant_exchange_id", table_name="participant")
|
||||
op.drop_index("idx_participant_exchange_email", table_name="participant")
|
||||
op.drop_index("idx_participant_email", table_name="participant")
|
||||
op.drop_table("participant")
|
||||
op.drop_index(op.f("ix_rate_limit_key"), table_name="rate_limit")
|
||||
op.drop_table("rate_limit")
|
||||
op.drop_index(op.f("ix_exchange_state"), table_name="exchange")
|
||||
op.drop_index(op.f("ix_exchange_slug"), table_name="exchange")
|
||||
op.drop_index(op.f("ix_exchange_completed_at"), table_name="exchange")
|
||||
op.drop_table("exchange")
|
||||
op.drop_index(op.f("ix_admin_email"), table_name="admin")
|
||||
op.drop_table("admin")
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user