From 84da2eb489da5c34c0e97ab7cb4566dee6dc667a Mon Sep 17 00:00:00 2001 From: Kobe Date: Tue, 24 Jun 2025 14:42:46 +0200 Subject: [PATCH] Update 9206bf87bb8e_add_portainer_stack_fields_to_instances.py --- ...add_portainer_stack_fields_to_instances.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/migrations/versions/9206bf87bb8e_add_portainer_stack_fields_to_instances.py b/migrations/versions/9206bf87bb8e_add_portainer_stack_fields_to_instances.py index ca5027f..5ca1934 100644 --- a/migrations/versions/9206bf87bb8e_add_portainer_stack_fields_to_instances.py +++ b/migrations/versions/9206bf87bb8e_add_portainer_stack_fields_to_instances.py @@ -7,6 +7,7 @@ Create Date: 2025-06-24 14:02:17.375785 """ from alembic import op import sqlalchemy as sa +from sqlalchemy import text # revision identifiers, used by Alembic. @@ -17,12 +18,23 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### + conn = op.get_bind() + + # Check if columns already exist + result = conn.execute(text(""" + SELECT column_name + FROM information_schema.columns + WHERE table_name = 'instances' + AND column_name IN ('portainer_stack_id', 'portainer_stack_name') + """)) + existing_columns = [row[0] for row in result.fetchall()] + + # Add portainer stack columns if they don't exist with op.batch_alter_table('instances', schema=None) as batch_op: - batch_op.add_column(sa.Column('portainer_stack_id', sa.String(length=100), nullable=True)) - batch_op.add_column(sa.Column('portainer_stack_name', sa.String(length=100), nullable=True)) - - # ### end Alembic commands ### + if 'portainer_stack_id' not in existing_columns: + batch_op.add_column(sa.Column('portainer_stack_id', sa.String(length=100), nullable=True)) + if 'portainer_stack_name' not in existing_columns: + batch_op.add_column(sa.Column('portainer_stack_name', sa.String(length=100), nullable=True)) def downgrade():