From c524b2485bb62444bc28c3e24eb304ade22fc2d6 Mon Sep 17 00:00:00 2001 From: Matthias Lodner Date: Wed, 4 Feb 2026 03:29:32 +0100 Subject: [PATCH] Removed null constrain from variant name and added query for bartender. --- bartender/README.md | 29 +++++++++++++++++-- .../20260204014610_rm_variant_name_null.sql | 4 +++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 server/migrations/20260204014610_rm_variant_name_null.sql diff --git a/bartender/README.md b/bartender/README.md index 5278d7e..a4c72a7 100644 --- a/bartender/README.md +++ b/bartender/README.md @@ -3,8 +3,28 @@ --- ## SQL +Query to get all articles with their variants and corresponding setting values. +COALESCE to select between two values where one is not null, if both are null first value is used. +With this default values are overridden. +```SQL +SELECT a.name AS product, + CONCAT(CONCAT(v.weight, ' '), u.display) AS weight, + a.bio AS bio, + COALESCE(v.description, a.description) AS description, + COALESCE(v.ingredients, a.ingredients) AS ingredients, + COALESCE(v.name, a.name) AS name, + COALESCE(a.bio_origin, s.bio) AS "bio origin", + COALESCE(a.mhd, s.mhd) AS mhd, + COALESCE(a.allergens_text, s.allergens_text) AS "allergens info" +FROM article AS a +INNER JOIN variant AS v ON v.article_id = a.id +INNER JOIN settings AS s ON v.article_id = v.article_id +INNER JOIN unit AS u ON v.unit_id = u.id +INNER JOIN label AS l ON v.label_id = l.id +ORDER BY a.name, v.weight ASC +``` --- @@ -16,8 +36,13 @@

``` +### Ingredients +```html + +``` + ### Allergens info ```html - - +

+

``` diff --git a/server/migrations/20260204014610_rm_variant_name_null.sql b/server/migrations/20260204014610_rm_variant_name_null.sql new file mode 100644 index 0000000..84a4301 --- /dev/null +++ b/server/migrations/20260204014610_rm_variant_name_null.sql @@ -0,0 +1,4 @@ +-- Add migration script here + +ALTER TABLE IF EXISTS public.variant + ALTER COLUMN name DROP NOT NULL;