Skip to content

Commit 6744723

Browse files
Make first Alembic migration idempotent for existing databases
Production DB already has refresh_schedule and last_refreshed_at columns (created with the initial table). The migration now checks for column existence before adding, so alembic upgrade head works on both fresh and existing databases. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fae8fdf commit 6744723

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

alembic/versions/c8b5dd2aff5e_add_refresh_schedule_and_last_refreshed_.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919

2020

2121
def upgrade() -> None:
22-
op.add_column("sources", sa.Column("refresh_schedule", sa.String(20), nullable=True))
23-
op.add_column("sources", sa.Column("last_refreshed_at", sa.DateTime(), nullable=True))
22+
conn = op.get_bind()
23+
inspector = sa.inspect(conn)
24+
columns = {c["name"] for c in inspector.get_columns("sources")}
25+
if "refresh_schedule" not in columns:
26+
op.add_column("sources", sa.Column("refresh_schedule", sa.String(20), nullable=True))
27+
if "last_refreshed_at" not in columns:
28+
op.add_column("sources", sa.Column("last_refreshed_at", sa.DateTime(), nullable=True))
2429

2530

2631
def downgrade() -> None:

0 commit comments

Comments
 (0)