From e4b1f5b963d97d71db4f168ebda1b5cb44d239de Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 30 Jul 2024 08:50:20 -0700 Subject: [PATCH] fix index attempt migration where no credential ID --- ...6ec550_associate_index_attempts_with_ccpair.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/alembic/versions/8a87bd6ec550_associate_index_attempts_with_ccpair.py b/backend/alembic/versions/8a87bd6ec550_associate_index_attempts_with_ccpair.py index 6865ed10c..ae0d4d3cd 100644 --- a/backend/alembic/versions/8a87bd6ec550_associate_index_attempts_with_ccpair.py +++ b/backend/alembic/versions/8a87bd6ec550_associate_index_attempts_with_ccpair.py @@ -35,9 +35,18 @@ def upgrade() -> None: op.execute( """ UPDATE index_attempt ia - SET connector_credential_pair_id = ccp.id - FROM connector_credential_pair ccp - WHERE ia.connector_id = ccp.connector_id AND ia.credential_id = ccp.credential_id + SET connector_credential_pair_id = + CASE + WHEN ia.credential_id IS NULL THEN + (SELECT id FROM connector_credential_pair + WHERE connector_id = ia.connector_id + LIMIT 1) + ELSE + (SELECT id FROM connector_credential_pair + WHERE connector_id = ia.connector_id + AND credential_id = ia.credential_id) + END + WHERE ia.connector_id IS NOT NULL """ )