From c8beeaf1b10b87e0c6fe013d07a9a993bdd7b452 Mon Sep 17 00:00:00 2001 From: mguschin Date: Mon, 9 Mar 2026 17:25:36 +0300 Subject: [PATCH] Fix migration to skip already-existing evotor_user_id column/indexes Co-Authored-By: Claude Sonnet 4.6 --- .../f6a7b8c9d0e1_evotor_webhook_token_flow.py | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/web/migrations/versions/f6a7b8c9d0e1_evotor_webhook_token_flow.py b/web/migrations/versions/f6a7b8c9d0e1_evotor_webhook_token_flow.py index d2b7671..3d31566 100644 --- a/web/migrations/versions/f6a7b8c9d0e1_evotor_webhook_token_flow.py +++ b/web/migrations/versions/f6a7b8c9d0e1_evotor_webhook_token_flow.py @@ -16,12 +16,31 @@ depends_on = None def upgrade() -> None: - op.add_column('evotor_connections', - sa.Column('evotor_user_id', sa.String(255), nullable=True)) - op.create_unique_constraint('uq_evotor_connections_evotor_user_id', - 'evotor_connections', ['evotor_user_id']) - op.create_index('ix_evotor_connections_evotor_user_id', - 'evotor_connections', ['evotor_user_id']) + conn = op.get_bind() + + # Check existing columns + columns = [row[0] for row in conn.execute(sa.text( + "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'evotor_connections'" + ))] + + if 'evotor_user_id' not in columns: + op.add_column('evotor_connections', + sa.Column('evotor_user_id', sa.String(255), nullable=True)) + + # Check existing indexes + indexes = [row[2] for row in conn.execute(sa.text( + "SHOW INDEX FROM evotor_connections" + ))] + + if 'uq_evotor_connections_evotor_user_id' not in indexes: + op.create_unique_constraint('uq_evotor_connections_evotor_user_id', + 'evotor_connections', ['evotor_user_id']) + + if 'ix_evotor_connections_evotor_user_id' not in indexes: + op.create_index('ix_evotor_connections_evotor_user_id', + 'evotor_connections', ['evotor_user_id']) + op.alter_column('evotor_connections', 'user_id', nullable=True)