71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
"""add account email tokens
|
|
|
|
Revision ID: 7a4e1b9c2d3f
|
|
Revises: 0f62f2706427
|
|
Create Date: 2026-08-28
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = "7a4e1b9c2d3f"
|
|
down_revision = "0f62f2706427"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
with op.batch_alter_table("user", schema=None) as batch_op:
|
|
batch_op.add_column(
|
|
sa.Column("email_verified_at", sa.DateTime(), nullable=True)
|
|
)
|
|
batch_op.drop_index(batch_op.f("ix_user_reset_password_code"))
|
|
batch_op.drop_column("reset_password_expiration")
|
|
batch_op.drop_column("reset_password_code")
|
|
|
|
op.create_table(
|
|
"account_token",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("purpose", sa.String(length=32), nullable=False),
|
|
sa.Column("token_hash", sa.String(length=64), nullable=False),
|
|
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(["user_id"], ["user.id"]),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("token_hash"),
|
|
)
|
|
with op.batch_alter_table("account_token", schema=None) as batch_op:
|
|
batch_op.create_index(
|
|
batch_op.f("ix_account_token_expires_at"), ["expires_at"]
|
|
)
|
|
batch_op.create_index(
|
|
batch_op.f("ix_account_token_purpose"), ["purpose"]
|
|
)
|
|
batch_op.create_index(
|
|
batch_op.f("ix_account_token_user_id"), ["user_id"]
|
|
)
|
|
|
|
|
|
def downgrade():
|
|
with op.batch_alter_table("account_token", schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f("ix_account_token_user_id"))
|
|
batch_op.drop_index(batch_op.f("ix_account_token_purpose"))
|
|
batch_op.drop_index(batch_op.f("ix_account_token_expires_at"))
|
|
op.drop_table("account_token")
|
|
with op.batch_alter_table("user", schema=None) as batch_op:
|
|
batch_op.add_column(
|
|
sa.Column("reset_password_code", sa.String(length=8), nullable=True)
|
|
)
|
|
batch_op.add_column(
|
|
sa.Column("reset_password_expiration", sa.DateTime(), nullable=True)
|
|
)
|
|
batch_op.create_index(
|
|
batch_op.f("ix_user_reset_password_code"),
|
|
["reset_password_code"],
|
|
unique=True,
|
|
)
|
|
batch_op.drop_column("email_verified_at")
|