From f3a4437acd4459fd38efd86c5a8d8d777afe4c41 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Thu, 25 Jun 2026 03:55:49 +0530 Subject: [PATCH] feat(oauth): add checks for oauth_account table existence before migration --- ...migrate_google_oauth_account_ids_to_sub.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/surfsense_backend/alembic/versions/169_migrate_google_oauth_account_ids_to_sub.py b/surfsense_backend/alembic/versions/169_migrate_google_oauth_account_ids_to_sub.py index c08ea2b22..76be1fb66 100644 --- a/surfsense_backend/alembic/versions/169_migrate_google_oauth_account_ids_to_sub.py +++ b/surfsense_backend/alembic/versions/169_migrate_google_oauth_account_ids_to_sub.py @@ -6,6 +6,7 @@ Revises: 168 from collections.abc import Sequence +import sqlalchemy as sa from alembic import op revision: str = "169" @@ -14,7 +15,28 @@ branch_labels: str | Sequence[str] | None = None depends_on: str | Sequence[str] | None = None +def _oauth_account_table_exists() -> bool: + bind = op.get_bind() + return bool( + bind.execute( + sa.text( + """ + SELECT EXISTS ( + SELECT 1 + FROM information_schema.tables + WHERE table_schema = current_schema() + AND table_name = 'oauth_account' + ) + """ + ) + ).scalar() + ) + + def upgrade() -> None: + if not _oauth_account_table_exists(): + return + op.execute( """ UPDATE oauth_account AS legacy @@ -32,6 +54,9 @@ def upgrade() -> None: def downgrade() -> None: + if not _oauth_account_table_exists(): + return + op.execute( """ UPDATE oauth_account AS canonical