5c38a6cc89
CI / lint (push) Successful in 13s
CI / audit (push) Successful in 11s
CI / e2e (push) Successful in 45s
CI / lighthouse (push) Successful in 58s
CI / test (push) Successful in 13s
CI / build-and-push-api (push) Successful in 2m45s
CI / deploy-dev (push) Has been cancelled
CI / deploy-uat (push) Has been cancelled
CI / build-and-push (push) Has been cancelled
CI / build-and-push-receiptwitness (push) Has been cancelled
CI / build-and-push-auth (push) Has been cancelled
Co-authored-by: Savannah Savings <31+cs_savannah@noreply.git.farh.net> Co-committed-by: Savannah Savings <31+cs_savannah@noreply.git.farh.net>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Add email_inbound_token to users.
|
|
|
|
Revision ID: 001_add_email_inbound_token
|
|
Revises:
|
|
Create Date: 2026-04-02
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from alembic import op
|
|
|
|
revision: str = "001_add_email_inbound_token"
|
|
down_revision: str | None = None
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Same VARCHAR(32) alembic_version limitation as the api migrations; the
|
|
# common 002 revision id is 46 chars. Widen first so a fresh-DB upgrade can
|
|
# stamp it. Idempotent.
|
|
op.execute("ALTER TABLE alembic_version ALTER COLUMN version_num TYPE VARCHAR(128)")
|
|
|
|
op.add_column("users", sa.Column("email_inbound_token", sa.String(22), nullable=True))
|
|
op.create_unique_constraint("uq_users_email_inbound_token", "users", ["email_inbound_token"])
|
|
|
|
# Backfill existing users with generated tokens (PostgreSQL)
|
|
op.execute(
|
|
"UPDATE users SET email_inbound_token = "
|
|
"substring(replace(gen_random_uuid()::text, '-', ''), 1, 22) "
|
|
"WHERE email_inbound_token IS NULL"
|
|
)
|
|
|
|
# Alter to non-nullable
|
|
op.alter_column("users", "email_inbound_token", nullable=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_constraint("uq_users_email_inbound_token", "users", type_="unique")
|
|
op.drop_column("users", "email_inbound_token") |