Add some consistency checks to SQL model
This commit is contained in:
parent
03f74e76ca
commit
988849e598
1 changed files with 14 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue