From 443e877a591b224e581a1d187fa7b0e4794ee4f5 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Tue, 13 Jan 2026 20:13:50 +0200 Subject: [PATCH] Make migration 55 idempotent --- ...5_rename_google_drive_connector_to_file.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/surfsense_backend/alembic/versions/55_rename_google_drive_connector_to_file.py b/surfsense_backend/alembic/versions/55_rename_google_drive_connector_to_file.py index 9ce57d95f..baaf1991f 100644 --- a/surfsense_backend/alembic/versions/55_rename_google_drive_connector_to_file.py +++ b/surfsense_backend/alembic/versions/55_rename_google_drive_connector_to_file.py @@ -60,14 +60,28 @@ def downgrade() -> None: connection = op.get_bind() - connection.execute( + # Only update if the target enum value exists (it won't on fresh databases) + result = connection.execute( text( """ - UPDATE documents - SET document_type = 'GOOGLE_DRIVE_CONNECTOR' - WHERE document_type = 'GOOGLE_DRIVE_FILE'; + SELECT EXISTS ( + SELECT 1 FROM pg_type t + JOIN pg_enum e ON t.oid = e.enumtypid + WHERE t.typname = 'documenttype' AND e.enumlabel = 'GOOGLE_DRIVE_CONNECTOR' + ); """ ) ) + enum_exists = result.scalar() - connection.commit() + if enum_exists: + connection.execute( + text( + """ + UPDATE documents + SET document_type = 'GOOGLE_DRIVE_CONNECTOR' + WHERE document_type = 'GOOGLE_DRIVE_FILE'; + """ + ) + ) + connection.commit()