model channels
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
2025-09-05 14:16:47 +09:00
parent 8dc49261b1
commit a23ca87c84
2 changed files with 48 additions and 3 deletions

View File

@@ -0,0 +1,45 @@
"""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: создаём новую таблицу, копируем данные, удаляем старую, переименовываем новую
conn = op.get_bind()
# 1. Создать новую таблицу
op.create_table(
'channel_new',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('admin_id', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# 2. Если старая таблица есть, скопировать данные
result = conn.execute(sa.text("SELECT name FROM sqlite_master WHERE type='table' AND name='channel'")).fetchone()
if result:
conn.execute(sa.text("INSERT INTO channel_new (id, name, admin_id) SELECT id, name, admin_id FROM channel"))
op.drop_table('channel')
# 3. Переименовать новую таблицу
conn.execute(sa.text("ALTER TABLE channel_new RENAME TO channel"))
def downgrade() -> None:
"""Downgrade schema."""
op.drop_table('channel')