From 0774fc4407dd255bc5c01bd0304f05ea97f7351b Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Fri, 17 Jul 2026 00:59:41 +0200 Subject: [PATCH] fix: make migration 0020 idempotent (check column exists) --- .../versions/0020_notifications_updated_at.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/alembic/versions/0020_notifications_updated_at.py b/alembic/versions/0020_notifications_updated_at.py index 1b8783a..6bc8a0f 100644 --- a/alembic/versions/0020_notifications_updated_at.py +++ b/alembic/versions/0020_notifications_updated_at.py @@ -15,15 +15,23 @@ depends_on = None def upgrade() -> None: - op.add_column( - "notifications", - sa.Column( - "updated_at", - sa.DateTime(timezone=True), - nullable=False, - server_default=sa.func.now(), - ), + conn = op.get_bind() + result = conn.execute( + sa.text( + "SELECT column_name FROM information_schema.columns " + "WHERE table_name = 'notifications' AND column_name = 'updated_at'" + ) ) + if result.fetchone() is None: + op.add_column( + "notifications", + sa.Column( + "updated_at", + sa.DateTime(timezone=True), + nullable=False, + server_default=sa.func.now(), + ), + ) def downgrade() -> None: