Skip to content

Commit

Permalink
Added db migration version to create the missing monitored column in …
Browse files Browse the repository at this point in the history
…TableShows table of some old instances.
  • Loading branch information
morpheus65535 committed Dec 27, 2023
1 parent 72bd52c commit 7c40bfe
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions migrations/versions/30f37e2e15e1_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""empty message
Revision ID: 30f37e2e15e1
Revises: cee6a710cb71
Create Date: 2023-12-26 21:32:39.283484
"""
from alembic import op
import sqlalchemy as sa
from app.database import TableShows


# revision identifiers, used by Alembic.
revision = '30f37e2e15e1'
down_revision = 'cee6a710cb71'
branch_labels = None
depends_on = None

bind = op.get_context().bind
insp = sa.inspect(bind)
tables = insp.get_table_names()
sqlite = bind.engine.name == 'sqlite'


def column_exists(table_name, column_name):
columns = insp.get_columns(table_name)
return any(c["name"] == column_name for c in columns)


def upgrade():
if not column_exists('table_shows', 'monitored'):
with op.batch_alter_table('table_shows', schema=None) as batch_op:
batch_op.add_column(sa.Column('monitored', sa.Text(), nullable=True))
op.execute(sa.update(TableShows).values({TableShows.monitored: 'True'}))


def downgrade():
pass

0 comments on commit 7c40bfe

Please sign in to comment.