32 lines
962 B
Python
32 lines
962 B
Python
"""add league public key
|
|
|
|
Revision ID: 0002_league_public_key
|
|
Revises: 0001_public_foundation
|
|
Create Date: 2026-06-23
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = "0002_league_public_key"
|
|
down_revision = "0001_public_foundation"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column("leagues", sa.Column("public_key", sa.String(length=12), nullable=True))
|
|
op.execute("UPDATE leagues SET public_key = substr(replace(id, '-', ''), 1, 12) WHERE public_key IS NULL")
|
|
|
|
with op.batch_alter_table("leagues") as batch_op:
|
|
batch_op.alter_column("public_key", existing_type=sa.String(length=12), nullable=False)
|
|
batch_op.create_index("ix_leagues_public_key", ["public_key"], unique=True)
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table("leagues") as batch_op:
|
|
batch_op.drop_index("ix_leagues_public_key")
|
|
batch_op.drop_column("public_key")
|