diff options
author | morpheus65535 <[email protected]> | 2023-12-26 22:37:52 -0500 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2023-12-26 22:37:52 -0500 |
commit | 7c40bfec1e390552c6f54c93e7cc5336307ed237 (patch) | |
tree | 405d3fabececb070b323ee657454ce735c92f51c /migrations | |
parent | 72bd52ce79405cc8adca427d2f5887a50273839e (diff) | |
download | bazarr-7c40bfec1e390552c6f54c93e7cc5336307ed237.tar.gz bazarr-7c40bfec1e390552c6f54c93e7cc5336307ed237.zip |
Added db migration version to create the missing monitored column in TableShows table of some old instances.
Diffstat (limited to 'migrations')
-rw-r--r-- | migrations/versions/30f37e2e15e1_.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/migrations/versions/30f37e2e15e1_.py b/migrations/versions/30f37e2e15e1_.py new file mode 100644 index 000000000..039637c64 --- /dev/null +++ b/migrations/versions/30f37e2e15e1_.py @@ -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 |