Fix migrations
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '002_marathon_settings'
|
||||
@@ -17,16 +18,27 @@ 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 = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Add is_public column to marathons table (default False = private)
|
||||
op.add_column('marathons', sa.Column('is_public', sa.Boolean(), nullable=False, server_default='false'))
|
||||
if not column_exists('marathons', 'is_public'):
|
||||
op.add_column('marathons', sa.Column('is_public', sa.Boolean(), nullable=False, server_default='false'))
|
||||
|
||||
# Add game_proposal_mode column to marathons table
|
||||
# 'all_participants' - anyone can propose games (with moderation)
|
||||
# 'organizer_only' - only organizers can add games
|
||||
op.add_column('marathons', sa.Column('game_proposal_mode', sa.String(20), nullable=False, server_default='all_participants'))
|
||||
if not column_exists('marathons', 'game_proposal_mode'):
|
||||
op.add_column('marathons', sa.Column('game_proposal_mode', sa.String(20), nullable=False, server_default='all_participants'))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('marathons', 'game_proposal_mode')
|
||||
op.drop_column('marathons', 'is_public')
|
||||
if column_exists('marathons', 'game_proposal_mode'):
|
||||
op.drop_column('marathons', 'game_proposal_mode')
|
||||
if column_exists('marathons', 'is_public'):
|
||||
op.drop_column('marathons', 'is_public')
|
||||
|
||||
Reference in New Issue
Block a user