Files
mealprep/backend/src/main/resources/db/migration/V009__create_recipe.sql
Marcel Raddatz 10b4d567d3 Add Flyway migrations V001-V019 for all 18 tables
V001: pgcrypto + citext extensions, trigger_set_updated_at function.
V002-V019: tables in FK dependency order per data model v1.1.

Spec fixes incorporated:
- recipe: added created_at/updated_at (spec says all mutable tables
  carry audit timestamps, but ERD omitted them)
- shopping_list: added household_id FK for HouseholdContext scoping
- shopping_list_item: added checked_by FK (API returns checkedBy)
- cooking_log: omitted phantom week_plan_slot_id (in FK map but
  absent from ERD, API, and all journeys)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 20:56:25 +02:00

20 lines
945 B
SQL

CREATE TABLE recipe (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
household_id uuid NOT NULL REFERENCES household (id) ON DELETE CASCADE,
name varchar(200) NOT NULL,
serves smallint NOT NULL CHECK (serves BETWEEN 1 AND 20),
cook_time_min smallint NOT NULL CHECK (cook_time_min >= 0),
effort varchar(10) NOT NULL CHECK (effort IN ('easy', 'medium', 'hard')),
is_child_friendly boolean NOT NULL DEFAULT false,
hero_image_url varchar(500),
deleted_at timestamptz,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX idx_recipe_household ON recipe (household_id) WHERE deleted_at IS NULL;
CREATE TRIGGER set_recipe_updated_at
BEFORE UPDATE ON recipe
FOR EACH ROW EXECUTE FUNCTION trigger_set_updated_at();