Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit f313dda

Browse files
Fixes on migration ON_DELETE_CASCADE (#708)
* Added transaction explicitly to migration * Added pragma=off on migration
1 parent ceccd5a commit f313dda

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

migrations/versions/2025_01_21_0820-4dec3e456c9e_add_on_delete_cascade.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919

2020
def upgrade() -> None:
21+
# Turn off foreign key constraints for this migration
22+
op.execute("PRAGMA foreign_keys=off;")
23+
24+
# Begin transaction
25+
op.execute("BEGIN TRANSACTION;")
26+
2127
# To add ON DELETE CASCADE to the foreign key constraint, we need to
2228
# rename the table, create a new table with the constraint, and copy
2329
# the data over.
@@ -101,6 +107,13 @@ def upgrade() -> None:
101107
op.execute("CREATE INDEX idx_prompts_workspace_id ON prompts (workspace_id);")
102108
op.execute("CREATE INDEX idx_sessions_workspace_id ON sessions (active_workspace_id);")
103109

110+
# Finish transaction
111+
op.execute("COMMIT;")
112+
113+
# Turn on foreign key constraints after the migration. Just to be sure. This shouldn't
114+
# be necessary, since it should be specified at the beginning of every connection, doesn't hurt.
115+
op.execute("PRAGMA foreign_keys=on;")
116+
104117

105118
def downgrade() -> None:
106119
# Settings table

0 commit comments

Comments
 (0)