Files
post_bot/alembic/versions/7506a3320699_channel_table.py
Choi A.K. 3aabe99a4e
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
migrations fix
2025-09-05 14:27:07 +09:00

40 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""channel table
Revision ID: 7506a3320699
Revises: 69ef23ef1ed1
Create Date: 2025-09-05 14:12:37.430983
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table, column
# revision identifiers, used by Alembic.
revision: str = '7506a3320699'
down_revision: Union[str, Sequence[str], None] = '69ef23ef1ed1'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# Для SQLite: добавляем столбцы через ALTER TABLE
conn = op.get_bind()
# Добавить столбец link, если его нет
result = conn.execute(sa.text("PRAGMA table_info(channels)")).fetchall()
columns = [row[1] for row in result]
if 'link' not in columns:
conn.execute(sa.text("ALTER TABLE channels ADD COLUMN link VARCHAR(255)"))
# Добавить столбец admin_id, если его нет
if 'admin_id' not in columns:
conn.execute(sa.text("ALTER TABLE channels ADD COLUMN admin_id INTEGER"))
def downgrade() -> None:
"""Downgrade schema."""
# SQLite не поддерживает удаление столбцов, поэтому просто удаляем таблицу
op.drop_table('channels')