first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
42
backend/alembic/versions/20260404_0009_digital_tickets.py
Normal file
42
backend/alembic/versions/20260404_0009_digital_tickets.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""digital ticket qr tokens and used status
|
||||
|
||||
Revision ID: 20260404_0009
|
||||
Revises: 20260404_0008
|
||||
"""
|
||||
|
||||
import secrets
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20260404_0009"
|
||||
down_revision: Union[str, None] = "20260404_0008"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute("ALTER TYPE ticketstatus RENAME VALUE 'redeemed' TO 'used'")
|
||||
|
||||
op.add_column("tickets", sa.Column("qr_token", sa.String(length=64), nullable=True))
|
||||
op.add_column("tickets", sa.Column("used_at", sa.DateTime(timezone=True), nullable=True))
|
||||
|
||||
connection = op.get_bind()
|
||||
rows = connection.execute(sa.text("SELECT id FROM tickets WHERE qr_token IS NULL")).fetchall()
|
||||
for row in rows:
|
||||
token = secrets.token_urlsafe(32)
|
||||
connection.execute(
|
||||
sa.text("UPDATE tickets SET qr_token = :token WHERE id = :id"),
|
||||
{"token": token, "id": row.id},
|
||||
)
|
||||
|
||||
op.alter_column("tickets", "qr_token", nullable=False)
|
||||
op.create_index(op.f("ix_tickets_qr_token"), "tickets", ["qr_token"], unique=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_tickets_qr_token"), table_name="tickets")
|
||||
op.drop_column("tickets", "used_at")
|
||||
op.drop_column("tickets", "qr_token")
|
||||
op.execute("ALTER TYPE ticketstatus RENAME VALUE 'used' TO 'redeemed'")
|
||||
Loading…
Add table
Add a link
Reference in a new issue