2025-12-21 02:52:48 +07:00
|
|
|
"""Add marathon cover_url field
|
|
|
|
|
|
|
|
|
|
Revision ID: 019_add_marathon_cover
|
|
|
|
|
Revises: 018_seed_static_content
|
|
|
|
|
Create Date: 2024-12-21
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
from typing import Sequence, Union
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
from sqlalchemy import inspect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
|
|
|
revision: str = '019_add_marathon_cover'
|
|
|
|
|
down_revision: Union[str, None] = '018_seed_static_content'
|
|
|
|
|
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:
|
2025-12-21 04:22:59 +07:00
|
|
|
if not column_exists('marathons', 'cover_path'):
|
|
|
|
|
op.add_column('marathons', sa.Column('cover_path', sa.String(500), nullable=True))
|
2025-12-21 02:52:48 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade() -> None:
|
2025-12-21 04:22:59 +07:00
|
|
|
if column_exists('marathons', 'cover_path'):
|
|
|
|
|
op.drop_column('marathons', 'cover_path')
|