From 24dff5f8754927e2c40756e4cf3deef68af08400 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 13 Aug 2025 21:18:33 +0200 Subject: [PATCH] fix linkup enum migration file --- .../alembic/versions/4_add_linkup_api_enum.py | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/surfsense_backend/alembic/versions/4_add_linkup_api_enum.py b/surfsense_backend/alembic/versions/4_add_linkup_api_enum.py index 26acec3..e11c89c 100644 --- a/surfsense_backend/alembic/versions/4_add_linkup_api_enum.py +++ b/surfsense_backend/alembic/versions/4_add_linkup_api_enum.py @@ -2,7 +2,7 @@ Revision ID: 4 Revises: 3 - +Create Date: 2025-08-13 """ from collections.abc import Sequence @@ -17,31 +17,29 @@ depends_on: str | Sequence[str] | None = None def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - - # Manually add the command to add the enum value - op.execute("ALTER TYPE searchsourceconnectortype ADD VALUE 'LINKUP_API'") - - # Pass for the rest, as autogenerate didn't run to add other schema details - pass - # ### end Alembic commands ### + # Add enum value only if it doesn't already exist. + # Postgres will no-op with a NOTICE when the value is present. + op.execute( + "ALTER TYPE searchsourceconnectortype ADD VALUE IF NOT EXISTS 'LINKUP_API'" + ) def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - - # Downgrading removal of an enum value requires recreating the type + # To "remove" an enum value in Postgres, we must recreate the type + # without that value, migrate the column, then drop the old type. op.execute( "ALTER TYPE searchsourceconnectortype RENAME TO searchsourceconnectortype_old" ) op.execute( - "CREATE TYPE searchsourceconnectortype AS ENUM('SERPER_API', 'TAVILY_API', 'SLACK_CONNECTOR', 'NOTION_CONNECTOR', 'GITHUB_CONNECTOR', 'LINEAR_CONNECTOR')" + "CREATE TYPE searchsourceconnectortype AS ENUM(" + "'SERPER_API', 'TAVILY_API', 'SLACK_CONNECTOR', " + "'NOTION_CONNECTOR', 'GITHUB_CONNECTOR', 'LINEAR_CONNECTOR'" + ")" ) op.execute( - "ALTER TABLE search_source_connectors ALTER COLUMN connector_type TYPE searchsourceconnectortype USING " - "connector_type::text::searchsourceconnectortype" + "ALTER TABLE search_source_connectors " + "ALTER COLUMN connector_type " + "TYPE searchsourceconnectortype " + "USING connector_type::text::searchsourceconnectortype" ) op.execute("DROP TYPE searchsourceconnectortype_old") - - pass - # ### end Alembic commands ###