From 72816d6b35782a3caf15ddbbbcbdb17957493d65 Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Sun, 19 Apr 2026 14:49:42 +0200 Subject: [PATCH] feat(schema): ingredient.section_heading (Migration 012 + Type) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fuegt das nullable Feld section_heading zur ingredient-Tabelle hinzu (Migration 012), erweitert den Ingredient-Typ und aktualisiert alle drei Return-Stellen in parseIngredient. Downstream-Sites (repository, Editor, Tests) bleiben rot – werden in Task 2+ behoben. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/server/db/migrations/012_ingredient_section.sql | 4 ++++ src/lib/server/parsers/ingredient.ts | 6 +++--- src/lib/types.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/lib/server/db/migrations/012_ingredient_section.sql diff --git a/src/lib/server/db/migrations/012_ingredient_section.sql b/src/lib/server/db/migrations/012_ingredient_section.sql new file mode 100644 index 0000000..deb1568 --- /dev/null +++ b/src/lib/server/db/migrations/012_ingredient_section.sql @@ -0,0 +1,4 @@ +-- Nullable -- old rows keep NULL, new rows may have a section heading. +-- Rendering rule: if section_heading is set (not NULL and not empty), +-- a new section with this title starts at this ingredient row. +ALTER TABLE ingredient ADD COLUMN section_heading TEXT; diff --git a/src/lib/server/parsers/ingredient.ts b/src/lib/server/parsers/ingredient.ts index 51230fc..8d28b83 100644 --- a/src/lib/server/parsers/ingredient.ts +++ b/src/lib/server/parsers/ingredient.ts @@ -105,16 +105,16 @@ export function parseIngredient(raw: string, position = 0): Ingredient { if (tail.length > 0) { const quantity = clampQuantity(UNICODE_FRACTION_MAP[firstChar]); const { unit, name } = splitUnitAndName(tail); - return { position, quantity, unit, name, note, raw_text: rawText }; + return { position, quantity, unit, name, note, raw_text: rawText, section_heading: null }; } } const qtyPattern = /^((?:\d+[.,]?\d*(?:\s*[-–]\s*\d+[.,]?\d*)?)|(?:\d+\/\d+))\s+(.+)$/; const qtyMatch = qtyPattern.exec(working); if (!qtyMatch) { - return { position, quantity: null, unit: null, name: working, note, raw_text: rawText }; + return { position, quantity: null, unit: null, name: working, note, raw_text: rawText, section_heading: null }; } const quantity = clampQuantity(parseQuantity(qtyMatch[1])); const { unit, name } = splitUnitAndName(qtyMatch[2]); - return { position, quantity, unit, name, note, raw_text: rawText }; + return { position, quantity, unit, name, note, raw_text: rawText, section_heading: null }; } diff --git a/src/lib/types.ts b/src/lib/types.ts index c2d63d2..4be0532 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -5,6 +5,7 @@ export type Ingredient = { name: string; note: string | null; raw_text: string; + section_heading: string | null; }; export type Step = {