Compare commits

...

2 Commits

Author SHA1 Message Date
1c87721611 Merge pull request 'migration fix' (#6) from v2 into main
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #6
2025-09-05 05:23:12 +00:00
a91283b681 migration fix
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2025-09-05 14:22:41 +09:00

View File

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