diff options
author | morpheus65535 <[email protected]> | 2024-07-04 23:12:58 -0400 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2024-07-04 23:12:58 -0400 |
commit | 1eec5490e5b673dec02c551d1c8cd8fdf09cd126 (patch) | |
tree | dab19784a464210796b311fb9d312d362b91b565 | |
parent | c8e34d424bf69d23534d81fc75ae02a092d43e39 (diff) | |
download | bazarr-1eec5490e5b673dec02c551d1c8cd8fdf09cd126.tar.gz bazarr-1eec5490e5b673dec02c551d1c8cd8fdf09cd126.zip |
no log: quick fix
-rw-r--r-- | migrations/versions/1e38aa77a491_.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/migrations/versions/1e38aa77a491_.py b/migrations/versions/1e38aa77a491_.py index 7e0c279c7..d1336dc74 100644 --- a/migrations/versions/1e38aa77a491_.py +++ b/migrations/versions/1e38aa77a491_.py @@ -15,24 +15,37 @@ down_revision = '452dd0f0b578' 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(): - with op.batch_alter_table('table_history', schema=None) as batch_op: - batch_op.add_column(sa.Column('upgradedFromId', sa.Integer(), nullable=True)) - batch_op.create_foreign_key(constraint_name='fk_history_upgradedFromId_id', - referent_table='table_history', - local_cols=['upgradedFromId'], - remote_cols=['id']) - - with op.batch_alter_table('table_history_movie', schema=None) as batch_op: - batch_op.add_column(sa.Column('upgradedFromId', sa.Integer(), nullable=True)) - batch_op.create_foreign_key(constraint_name='fk_history_movie_upgradedFromId_id', - referent_table='table_history_movie', - local_cols=['upgradedFromId'], - remote_cols=['id']) - - with op.batch_alter_table('table_languages_profiles', schema=None) as batch_op: - batch_op.add_column(sa.Column('tag', sa.Text(), nullable=True)) + if not column_exists('table_history', 'upgradedFromId'): + with op.batch_alter_table('table_history', schema=None) as batch_op: + batch_op.add_column(sa.Column('upgradedFromId', sa.Integer(), nullable=True)) + batch_op.create_foreign_key(constraint_name='fk_history_upgradedFromId_id', + referent_table='table_history', + local_cols=['upgradedFromId'], + remote_cols=['id']) + + if not column_exists('table_history_movie', 'upgradedFromId'): + with op.batch_alter_table('table_history_movie', schema=None) as batch_op: + batch_op.add_column(sa.Column('upgradedFromId', sa.Integer(), nullable=True)) + batch_op.create_foreign_key(constraint_name='fk_history_movie_upgradedFromId_id', + referent_table='table_history_movie', + local_cols=['upgradedFromId'], + remote_cols=['id']) + + if not column_exists('table_languages_profiles', 'tag'): + with op.batch_alter_table('table_languages_profiles', schema=None) as batch_op: + batch_op.add_column(sa.Column('tag', sa.Text(), nullable=True)) def downgrade(): |