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

Added pragma on file connections and DROP TABLE IF EXISTS #706

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def run_migrations_offline() -> None:
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
transactional_ddl=True,
)

with context.begin_transaction():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def upgrade() -> None:
# 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.
op.execute("DROP TABLE IF EXISTS _prompts_old;")
op.execute("ALTER TABLE prompts RENAME TO _prompts_old;")
op.execute(
"""
Expand All @@ -39,6 +40,7 @@ def upgrade() -> None:
op.execute("DROP TABLE _prompts_old;")

# Doing the same for the sessions table
op.execute("DROP TABLE IF EXISTS _sessions_old;")
op.execute("ALTER TABLE sessions RENAME TO _sessions_old;")
op.execute(
"""
Expand All @@ -54,6 +56,7 @@ def upgrade() -> None:
op.execute("DROP TABLE _sessions_old;")

# Doing the same for the output table
op.execute("DROP TABLE IF EXISTS _outputs_old;")
op.execute("ALTER TABLE outputs RENAME TO _outputs_old;")
op.execute(
"""
Expand All @@ -70,6 +73,7 @@ def upgrade() -> None:
op.execute("DROP TABLE _outputs_old;")

# Doing the same for the alerts table
op.execute("DROP TABLE IF EXISTS _alerts_old;")
op.execute("ALTER TABLE alerts RENAME TO _alerts_old;")
op.execute(
"""
Expand All @@ -89,7 +93,7 @@ def upgrade() -> None:
op.execute("DROP TABLE _alerts_old;")

# Dropping unused table
op.execute("DROP TABLE settings;")
op.execute("DROP TABLE IF EXISTS settings;")

# Create indexes for foreign keys
op.execute("CREATE INDEX idx_outputs_prompt_id ON outputs(prompt_id);")
Expand Down
Loading