Skip to content

Commit 868afe6

Browse files
Added pragma on file connections and DROP TABLE IF EXISTS (#706)
* Added pragma on file connections and DROP TABLE IF EXISTS * Changed comment * Formatting changes * Changes to PRAGMA
1 parent a2b53b3 commit 868afe6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

migrations/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def run_migrations_offline() -> None:
3535
target_metadata=target_metadata,
3636
literal_binds=True,
3737
dialect_opts={"paramstyle": "named"},
38+
transactional_ddl=True,
3839
)
3940

4041
with context.begin_transaction():

migrations/versions/2025_01_21_0820-4dec3e456c9e_add_on_delete_cascade.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def upgrade() -> None:
2121
# To add ON DELETE CASCADE to the foreign key constraint, we need to
2222
# rename the table, create a new table with the constraint, and copy
2323
# the data over.
24+
op.execute("DROP TABLE IF EXISTS _prompts_old;")
2425
op.execute("ALTER TABLE prompts RENAME TO _prompts_old;")
2526
op.execute(
2627
"""
@@ -39,6 +40,7 @@ def upgrade() -> None:
3940
op.execute("DROP TABLE _prompts_old;")
4041

4142
# Doing the same for the sessions table
43+
op.execute("DROP TABLE IF EXISTS _sessions_old;")
4244
op.execute("ALTER TABLE sessions RENAME TO _sessions_old;")
4345
op.execute(
4446
"""
@@ -54,6 +56,7 @@ def upgrade() -> None:
5456
op.execute("DROP TABLE _sessions_old;")
5557

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

7275
# Doing the same for the alerts table
76+
op.execute("DROP TABLE IF EXISTS _alerts_old;")
7377
op.execute("ALTER TABLE alerts RENAME TO _alerts_old;")
7478
op.execute(
7579
"""
@@ -89,7 +93,7 @@ def upgrade() -> None:
8993
op.execute("DROP TABLE _alerts_old;")
9094

9195
# Dropping unused table
92-
op.execute("DROP TABLE settings;")
96+
op.execute("DROP TABLE IF EXISTS settings;")
9397

9498
# Create indexes for foreign keys
9599
op.execute("CREATE INDEX idx_outputs_prompt_id ON outputs(prompt_id);")

0 commit comments

Comments
 (0)