From 26e7d8060f5b2377a2bf48518169b17aea38b23c Mon Sep 17 00:00:00 2001 From: Rohit Malhotra Date: Thu, 20 Nov 2025 06:21:40 -0500 Subject: [PATCH] fix(migrations): make SETTING_UP_SKILLS enum migration idempotent (#11782) Co-authored-by: openhands Co-authored-by: Tim O'Farrell --- .../082_add_setting_up_skills_enum_value.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/enterprise/migrations/versions/082_add_setting_up_skills_enum_value.py b/enterprise/migrations/versions/082_add_setting_up_skills_enum_value.py index 621767a2df..4f960acd27 100644 --- a/enterprise/migrations/versions/082_add_setting_up_skills_enum_value.py +++ b/enterprise/migrations/versions/082_add_setting_up_skills_enum_value.py @@ -9,6 +9,7 @@ Create Date: 2025-11-19 12:00:00.000000 from typing import Sequence, Union from alembic import op +from sqlalchemy import text # revision identifiers, used by Alembic. revision: str = '082' @@ -19,11 +20,22 @@ depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: """Add SETTING_UP_SKILLS enum value to appconversationstarttaskstatus.""" - # Add the new enum value to the existing enum type - op.execute( - "ALTER TYPE appconversationstarttaskstatus ADD VALUE 'SETTING_UP_SKILLS'" + # Check if the enum value already exists before adding it + # This handles the case where the enum was created with the value already included + connection = op.get_bind() + result = connection.execute( + text( + "SELECT 1 FROM pg_enum WHERE enumlabel = 'SETTING_UP_SKILLS' " + "AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'appconversationstarttaskstatus')" + ) ) + if not result.fetchone(): + # Add the new enum value only if it doesn't already exist + op.execute( + "ALTER TYPE appconversationstarttaskstatus ADD VALUE 'SETTING_UP_SKILLS'" + ) + def downgrade() -> None: """Remove SETTING_UP_SKILLS enum value from appconversationstarttaskstatus.