@@ -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