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

Fixes on migration ON_DELETE_CASCADE #708

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@


def upgrade() -> None:
# Turn off foreign key constraints for this migration
op.execute("PRAGMA foreign_keys=off;")

# Begin transaction
op.execute("BEGIN TRANSACTION;")

# To add ON DELETE CASCADE to the foreign key constraint, we need to
# rename the table, create a new table with the constraint, and copy
# the data over.
Expand Down Expand Up @@ -101,6 +107,13 @@ def upgrade() -> None:
op.execute("CREATE INDEX idx_prompts_workspace_id ON prompts (workspace_id);")
op.execute("CREATE INDEX idx_sessions_workspace_id ON sessions (active_workspace_id);")

# Finish transaction
op.execute("COMMIT;")

# Turn on foreign key constraints after the migration. Just to be sure. This shouldn't
# be necessary, since it should be specified at the beginning of every connection, doesn't hurt.
op.execute("PRAGMA foreign_keys=on;")


def downgrade() -> None:
# Settings table
Expand Down
Loading