Ingredients can now be manually ordered

This commit is contained in:
Greg Burri 2025-01-16 00:17:08 +01:00
parent afd42ba1d0
commit ca2227037f
11 changed files with 205 additions and 32 deletions

View file

@ -56,6 +56,7 @@ CREATE TABLE [Recipe] (
[lang] TEXT NOT NULL DEFAULT 'en',
[estimated_time] INTEGER, -- in [s].
[description] TEXT NOT NULL DEFAULT '',
-- 0: Unknown, 1: Easy, 2: Medium, 4: Hard.
[difficulty] INTEGER NOT NULL DEFAULT 0,
[servings] INTEGER DEFAULT 4,
[is_published] INTEGER NOT NULL DEFAULT FALSE,
@ -64,6 +65,28 @@ CREATE TABLE [Recipe] (
FOREIGN KEY([user_id]) REFERENCES [User]([id]) ON DELETE SET NULL
) STRICT;
CREATE TRIGGER [Recipe_trigger_update_difficulty]
BEFORE UPDATE OF [difficulty]
ON [Recipe]
BEGIN
SELECT
CASE
WHEN NEW.[difficulty] < 0 OR NEW.[difficulty] > 3 THEN
RAISE (ABORT, 'Invalid [difficulty] value')
END;
END;
CREATE TRIGGER [Recipe_trigger_insert_difficulty]
BEFORE INSERT
ON [Recipe]
BEGIN
SELECT
CASE
WHEN NEW.[difficulty] < 0 OR NEW.[difficulty] > 3 THEN
RAISE (ABORT, 'Invalid [difficulty] value')
END;
END;
CREATE TABLE [Image] (
[Id] INTEGER PRIMARY KEY,
[recipe_id] INTEGER NOT NULL,
@ -124,6 +147,7 @@ CREATE INDEX [Step_order_index] ON [Group]([order]);
CREATE TABLE [Ingredient] (
[id] INTEGER PRIMARY KEY,
[order] INTEGER NOT NULL DEFAULT 0,
[step_id] INTEGER NOT NULL,
[name] TEXT NOT NULL DEFAULT '',
@ -134,14 +158,4 @@ CREATE TABLE [Ingredient] (
FOREIGN KEY([step_id]) REFERENCES [Step]([id]) ON DELETE CASCADE
) STRICT;
-- CREATE TABLE [IntermediateSubstance] (
-- [id] INTEGER PRIMARY KEY,
-- [name] TEXT NOT NULL DEFAULT '',
-- [quantity_value] REAL,
-- [quantity_unit] TEXT NOT NULL DEFAULT '',
-- [output_group_id] INTEGER NOT NULL,
-- [input_group_id] INTEGER NOT NULL,
-- FOREIGN KEY([output_group_id]) REFERENCES [group]([id]) ON DELETE CASCADE,
-- FOREIGN KEY([input_group_id]) REFERENCES [group]([id]) ON DELETE CASCADE
-- ) STRICT;
CREATE INDEX [Ingredient_order_index] ON [Ingredient]([order]);