37 lines
994 B
Python
37 lines
994 B
Python
|
|
"""Add banned_until field
|
||
|
|
|
||
|
|
Revision ID: 016_add_banned_until
|
||
|
|
Revises: 015_add_static_content
|
||
|
|
Create Date: 2024-12-19
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from sqlalchemy import inspect
|
||
|
|
|
||
|
|
|
||
|
|
# revision identifiers, used by Alembic.
|
||
|
|
revision: str = '016_add_banned_until'
|
||
|
|
down_revision: Union[str, None] = '015_add_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:
|
||
|
|
if not column_exists('users', 'banned_until'):
|
||
|
|
op.add_column('users', sa.Column('banned_until', sa.DateTime(), nullable=True))
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
if column_exists('users', 'banned_until'):
|
||
|
|
op.drop_column('users', 'banned_until')
|