File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change
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
+ """
Original file line number Diff line number Diff line change @@ -694,7 +694,11 @@ class Connector(Base):
694
694
)
695
695
documents_by_connector : Mapped [
696
696
list ["DocumentByConnectorCredentialPair" ]
697
- ] = relationship ("DocumentByConnectorCredentialPair" , back_populates = "connector" )
697
+ ] = relationship (
698
+ "DocumentByConnectorCredentialPair" ,
699
+ back_populates = "connector" ,
700
+ cascade = "all, delete-orphan" ,
701
+ )
698
702
699
703
# synchronize this validation logic with RefreshFrequencySchema etc on front end
700
704
# until we have a centralized validation schema
You can’t perform that action at this time.
0 commit comments