Skip to content

Commit 1f280ba

Browse files
committed
quick fix
1 parent cb5bbd3 commit 1f280ba

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""add_cascade_delete_to_connector_documents
2+
3+
Revision ID: a31fc5e4d9c8
4+
Revises: 3bd4c84fe72f
5+
Create Date: 2025-03-29 12:00:00.000000
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = "a31fc5e4d9c8"
11+
down_revision = "3bd4c84fe72f"
12+
branch_labels = None
13+
depends_on = None
14+
15+
16+
def upgrade() -> None:
17+
"""
18+
This migration adds cascade delete to the relationship between Connector and
19+
DocumentByConnectorCredentialPair to fix an issue where deleting a Connector
20+
would fail because SQLAlchemy was trying to blank out primary key columns in
21+
DocumentByConnectorCredentialPair records instead of deleting them.
22+
23+
The actual change is in the model definition (models.py) where we've added
24+
cascade="all, delete-orphan" to the documents_by_connector relationship in
25+
the Connector model.
26+
27+
This is a metadata-only change and doesn't require schema modifications.
28+
"""
29+
# This is a metadata-only change to the SQLAlchemy model, no SQL needed
30+
31+
32+
def downgrade() -> None:
33+
"""
34+
No downgrade required as this is a metadata-only change
35+
"""

backend/onyx/db/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,11 @@ class Connector(Base):
694694
)
695695
documents_by_connector: Mapped[
696696
list["DocumentByConnectorCredentialPair"]
697-
] = relationship("DocumentByConnectorCredentialPair", back_populates="connector")
697+
] = relationship(
698+
"DocumentByConnectorCredentialPair",
699+
back_populates="connector",
700+
cascade="all, delete-orphan",
701+
)
698702

699703
# synchronize this validation logic with RefreshFrequencySchema etc on front end
700704
# until we have a centralized validation schema

0 commit comments

Comments
 (0)