Skip to content

Commit

Permalink
Added pragma on file connections and DROP TABLE IF EXISTS (#706)
Browse files Browse the repository at this point in the history
* Added pragma on file connections and DROP TABLE IF EXISTS

* Changed comment

* Formatting changes

* Changes to PRAGMA
  • Loading branch information
aponcedeleonch authored Jan 22, 2025
1 parent a2b53b3 commit 868afe6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit 868afe6

Please sign in to comment.