53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
|
|
"""Simplify boost consumable - make it one-time instead of timed
|
||
|
|
|
||
|
|
Revision ID: 025_simplify_boost
|
||
|
|
Revises: 024_seed_shop_items
|
||
|
|
Create Date: 2026-01-08
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from sqlalchemy import inspect
|
||
|
|
|
||
|
|
|
||
|
|
# revision identifiers, used by Alembic.
|
||
|
|
revision: str = '025_simplify_boost'
|
||
|
|
down_revision: Union[str, None] = '024_seed_shop_items'
|
||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
||
|
|
|
||
|
|
|
||
|
|
def column_exists(table_name: str, column_name: str) -> bool:
|
||
|
|
bind = op.get_bind()
|
||
|
|
inspector = inspect(bind)
|
||
|
|
columns = [c['name'] for c in inspector.get_columns(table_name)]
|
||
|
|
return column_name in columns
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
# Add new boolean column for one-time boost
|
||
|
|
if not column_exists('participants', 'has_active_boost'):
|
||
|
|
op.add_column('participants', sa.Column('has_active_boost', sa.Boolean(), nullable=False, server_default='false'))
|
||
|
|
|
||
|
|
# Remove old timed boost columns
|
||
|
|
if column_exists('participants', 'active_boost_multiplier'):
|
||
|
|
op.drop_column('participants', 'active_boost_multiplier')
|
||
|
|
|
||
|
|
if column_exists('participants', 'active_boost_expires_at'):
|
||
|
|
op.drop_column('participants', 'active_boost_expires_at')
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
# Restore old columns
|
||
|
|
if not column_exists('participants', 'active_boost_multiplier'):
|
||
|
|
op.add_column('participants', sa.Column('active_boost_multiplier', sa.Float(), nullable=True))
|
||
|
|
|
||
|
|
if not column_exists('participants', 'active_boost_expires_at'):
|
||
|
|
op.add_column('participants', sa.Column('active_boost_expires_at', sa.DateTime(), nullable=True))
|
||
|
|
|
||
|
|
# Remove new column
|
||
|
|
if column_exists('participants', 'has_active_boost'):
|
||
|
|
op.drop_column('participants', 'has_active_boost')
|