|
19 | 19 |
|
20 | 20 |
|
21 | 21 | def upgrade() -> None: |
22 | | - # ### commands auto generated by Alembic - please adjust! ### |
23 | | - with op.batch_alter_table('seasons', schema=None) as batch_op: |
24 | | - batch_op.add_column(sa.Column('emby_season_id', sa.String(length=100), nullable=True)) |
| 22 | + ### commands auto generated by Alembic - please adjust! ### |
| 23 | + conn = op.get_bind() |
| 24 | + inspector = sa.inspect(conn) |
| 25 | + existing_cols = [c['name'] for c in inspector.get_columns('seasons')] |
| 26 | + |
| 27 | + # only add the column if it doesn't already exist (makes migration idempotent) |
| 28 | + if 'emby_season_id' not in existing_cols: |
| 29 | + with op.batch_alter_table('seasons', schema=None) as batch_op: |
| 30 | + batch_op.add_column( |
| 31 | + sa.Column('emby_season_id', sa.String(length=100), nullable=True) |
| 32 | + ) |
25 | 33 |
|
26 | 34 | # ### end Alembic commands ### |
27 | 35 |
|
28 | 36 |
|
29 | 37 | def downgrade() -> None: |
30 | | - # ### commands auto generated by Alembic - please adjust! ### |
31 | | - with op.batch_alter_table('seasons', schema=None) as batch_op: |
32 | | - batch_op.drop_column('emby_season_id') |
| 38 | + ### commands auto generated by Alembic - please adjust! ### |
| 39 | + conn = op.get_bind() |
| 40 | + inspector = sa.inspect(conn) |
| 41 | + existing_cols = [c['name'] for c in inspector.get_columns('seasons')] |
| 42 | + |
| 43 | + # only drop the column if it exists |
| 44 | + if 'emby_season_id' in existing_cols: |
| 45 | + with op.batch_alter_table('seasons', schema=None) as batch_op: |
| 46 | + batch_op.drop_column('emby_season_id') |
33 | 47 |
|
34 | 48 | # ### end Alembic commands ### |
0 commit comments