From 2ffb3be1146a8c6977b741fc065755a24643febf Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 18 Jan 2023 07:40:10 -0500 Subject: [PATCH] Clean plan data on plan save --- kitchen/sqlx-data.json | 10 ++++++++++ kitchen/src/web/storage/mod.rs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/kitchen/sqlx-data.json b/kitchen/sqlx-data.json index 1f4f61b..17eba75 100644 --- a/kitchen/sqlx-data.json +++ b/kitchen/sqlx-data.json @@ -490,6 +490,16 @@ }, "query": "select session_value from sessions where id = ?" }, + "93af0c367a0913d49c92aa69022fa30fc0564bd4dbab7f3ae78673a01439cd6e": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Right": 2 + } + }, + "query": "delete from plan_recipes where user_id = ? and plan_date = ?" + }, "95fbc362a2e17add05218a2dac431275b5cc55bd7ac8f4173ee10afefceafa3b": { "describe": { "columns": [ diff --git a/kitchen/src/web/storage/mod.rs b/kitchen/src/web/storage/mod.rs index 1882a32..423c84a 100644 --- a/kitchen/src/web/storage/mod.rs +++ b/kitchen/src/web/storage/mod.rs @@ -534,6 +534,13 @@ impl APIStore for SqliteStore { ) -> Result<()> { let user_id = user_id.as_ref(); let mut transaction = self.pool.as_ref().begin().await?; + sqlx::query!( + "delete from plan_recipes where user_id = ? and plan_date = ?", + user_id, + date, + ) + .execute(&mut transaction) + .await?; for (id, count) in recipe_counts { sqlx::query_file!( "src/web/storage/save_meal_plan.sql",