PostgreSQL rejects BOOLEAN DEFAULT 0 (DatatypeMismatch: column ... is of type
boolean but default expression is of type integer). Migration 0008
(platform_settings.active) crashed the alembic upgrade run by the entrypoint,
which in turn crash-looped the worker. Migration 0011 (password_reset_tokens.
used) had the same latent bug and would have failed next.
Change the Boolean server_default from text('0') to text('false') in both
migrations and both ORM models so the DDL is valid on both PostgreSQL
(production) and SQLite (local/tests).
Verified: full 0001->0011 chain runs on fresh SQLite; alembic check reports no
drift; backend suite 201 passed.
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
"""Add durable, single-use password reset tokens."""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "0011_password_reset_tokens"
|
|
down_revision = "0010_usage_events"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"password_reset_tokens",
|
|
sa.Column("id", sa.String(length=64), nullable=False),
|
|
sa.Column("user_id", sa.String(length=64), nullable=False),
|
|
sa.Column("token_hash", sa.String(length=128), nullable=False),
|
|
sa.Column("auth_version", sa.Integer(), server_default=sa.text("0"), nullable=False),
|
|
sa.Column("used", sa.Boolean(), server_default=sa.text("false"), nullable=False),
|
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_password_reset_tokens_user_id", "password_reset_tokens", ["user_id"], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_password_reset_tokens_user_id", table_name="password_reset_tokens")
|
|
op.drop_table("password_reset_tokens")
|