diff --git a/backend/sql/version_1.sql b/backend/sql/version_1.sql index 2da0db8..4c75695 100644 --- a/backend/sql/version_1.sql +++ b/backend/sql/version_1.sql @@ -263,7 +263,16 @@ CREATE TABLE [ShoppingEntry] ( CHECK ( length([name]) <= 255 AND - ([is_checked] = TRUE OR [is_checked] = FALSE) + ([is_checked] = TRUE OR [is_checked] = FALSE) AND + ( + [recipe_scheduled_id] IS NULL OR + ( + [name] = '' AND + [quantity_value] IS NULL AND + [quantity_unit] = '' AND + [servings] IS NULL + ) + ) ), FOREIGN KEY([user_id]) REFERENCES [User]([id]) ON DELETE CASCADE, @@ -284,20 +293,21 @@ BEGIN [name] = OLD.[name], [quantity_value] = OLD.[quantity_value], [quantity_unit] = OLD.[quantity_unit], - [servings] = ( + [servings] = COALESCE(( SELECT [servings] FROM [Recipe] INNER JOIN [Group] ON [Group].[recipe_id] = [Recipe].[id] INNER JOIN [Step] ON [Step].[group_id] = [Group].[id] WHERE [Step].[id] = OLD.[step_id] - ) + LIMIT 1 -- In case a step is owned by more than one recipe (should never happen). + ), 4) WHERE [ingredient_id] = OLD.[id]; END; CREATE TABLE [Settings] ( [name] TEXT NOT NULL PRIMARY KEY, - -- Value can by anything that can be read from a text by + -- Value can be anything that can be read from a text by -- implementing the trait 'std::str::FromStr'. [value] TEXT NOT NULL ) STRICT;