From 45e1a9cb81efd1ce17517255153624e0daa6ec38 Mon Sep 17 00:00:00 2001 From: Kevin Schaul Date: Fri, 18 Aug 2023 16:30:47 -0500 Subject: [PATCH] Fix migration of foreign keys The tests currently fail, due to migration m008_reply_to_id_foreign_key failing. I suspect this is related to a recent change in squlite-utils [0]. This PR avoids that by explictly dropping the foreign key before renaming the table, then adding the foreign key back. See the related GitHub issue for more info [1]. [0] https://github.com/simonw/sqlite-utils/issues/577 [1] https://github.com/simonw/llm/issues/162 --- llm/migrations.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/llm/migrations.py b/llm/migrations.py index 378d3eca..50ee6aef 100644 --- a/llm/migrations.py +++ b/llm/migrations.py @@ -130,8 +130,10 @@ def m007_finish_logs_table(db): drop={"debug"}, rename={"timestamp_utc": "datetime_utc"}, ) + db["log"].transform(drop_foreign_keys=("chat_id",)) with db.conn: db.execute("alter table log rename to logs") + db["logs"].add_foreign_key("chat_id", "logs", "id") @migration