From edf587e79893d2609ecc1b88af2fc6c2ead9fb8e Mon Sep 17 00:00:00 2001 From: dbastrikin Date: Sun, 22 Mar 2026 21:52:26 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20squash=20migrations=20003=E2=80=93005?= =?UTF-8?q?=20into=20001=5Finitial=5Fschema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fold all incremental schema changes into the baseline migration so that a fresh database only needs to run one file: - recipe_source enum now includes 'menu' - recipe_products/recipe_product_translations renamed to recipe_ingredients/recipe_ingredient_translations; product_id → ingredient_id - menu_items.meal_type CHECK expanded to all 6 types (breakfast, second_breakfast, lunch, afternoon_snack, dinner, snack) Co-Authored-By: Claude Sonnet 4.6 --- backend/migrations/001_initial_schema.sql | 34 +++++++++---------- .../migrations/003_add_menu_recipe_source.sql | 5 --- .../migrations/004_rename_recipe_products.sql | 27 --------------- backend/migrations/005_partial_menu.sql | 12 ------- client/pubspec.lock | 20 +++++------ 5 files changed, 27 insertions(+), 71 deletions(-) delete mode 100644 backend/migrations/003_add_menu_recipe_source.sql delete mode 100644 backend/migrations/004_rename_recipe_products.sql delete mode 100644 backend/migrations/005_partial_menu.sql diff --git a/backend/migrations/001_initial_schema.sql b/backend/migrations/001_initial_schema.sql index 1e816eb..8c2cd2d 100644 --- a/backend/migrations/001_initial_schema.sql +++ b/backend/migrations/001_initial_schema.sql @@ -48,7 +48,7 @@ CREATE TYPE user_plan AS ENUM ('free', 'paid'); CREATE TYPE user_gender AS ENUM ('male', 'female'); CREATE TYPE user_goal AS ENUM ('lose', 'maintain', 'gain'); CREATE TYPE activity_level AS ENUM ('low', 'moderate', 'high'); -CREATE TYPE recipe_source AS ENUM ('spoonacular', 'ai', 'user'); +CREATE TYPE recipe_source AS ENUM ('spoonacular', 'ai', 'user', 'menu'); CREATE TYPE recipe_difficulty AS ENUM ('easy', 'medium', 'hard'); -- --------------------------------------------------------------------------- @@ -277,22 +277,22 @@ CREATE TABLE recipe_translations ( ); -- --------------------------------------------------------------------------- --- recipe_products + recipe_product_translations +-- recipe_ingredients + recipe_ingredient_translations -- --------------------------------------------------------------------------- -CREATE TABLE recipe_products ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v7(), - recipe_id UUID NOT NULL REFERENCES recipes(id) ON DELETE CASCADE, - product_id UUID REFERENCES products(id) ON DELETE SET NULL, - name TEXT NOT NULL, - amount DECIMAL(10,2) NOT NULL DEFAULT 0, - unit_code VARCHAR(20), - is_optional BOOLEAN NOT NULL DEFAULT false, - sort_order SMALLINT NOT NULL DEFAULT 0 +CREATE TABLE recipe_ingredients ( + id UUID PRIMARY KEY DEFAULT uuid_generate_v7(), + recipe_id UUID NOT NULL REFERENCES recipes(id) ON DELETE CASCADE, + ingredient_id UUID REFERENCES products(id) ON DELETE SET NULL, + name TEXT NOT NULL, + amount DECIMAL(10,2) NOT NULL DEFAULT 0, + unit_code VARCHAR(20), + is_optional BOOLEAN NOT NULL DEFAULT false, + sort_order SMALLINT NOT NULL DEFAULT 0 ); -CREATE INDEX idx_recipe_products_recipe_id ON recipe_products (recipe_id); +CREATE INDEX idx_recipe_ingredients_recipe_id ON recipe_ingredients (recipe_id); -CREATE TABLE recipe_product_translations ( - ri_id UUID NOT NULL REFERENCES recipe_products(id) ON DELETE CASCADE, +CREATE TABLE recipe_ingredient_translations ( + ri_id UUID NOT NULL REFERENCES recipe_ingredients(id) ON DELETE CASCADE, lang VARCHAR(10) NOT NULL, name TEXT NOT NULL, PRIMARY KEY (ri_id, lang) @@ -372,7 +372,7 @@ CREATE TABLE menu_items ( id UUID PRIMARY KEY DEFAULT uuid_generate_v7(), menu_plan_id UUID NOT NULL REFERENCES menu_plans(id) ON DELETE CASCADE, day_of_week INT NOT NULL CHECK (day_of_week BETWEEN 1 AND 7), - meal_type TEXT NOT NULL CHECK (meal_type IN ('breakfast','lunch','dinner')), + meal_type TEXT NOT NULL CHECK (meal_type IN ('breakfast','second_breakfast','lunch','afternoon_snack','dinner','snack')), recipe_id UUID REFERENCES recipes(id) ON DELETE SET NULL, dish_id UUID REFERENCES dishes(id) ON DELETE SET NULL, recipe_data JSONB, @@ -621,8 +621,8 @@ DROP TABLE IF EXISTS user_product_components; DROP TABLE IF EXISTS user_products; DROP TABLE IF EXISTS recipe_step_translations; DROP TABLE IF EXISTS recipe_steps; -DROP TABLE IF EXISTS recipe_product_translations; -DROP TABLE IF EXISTS recipe_products; +DROP TABLE IF EXISTS recipe_ingredient_translations; +DROP TABLE IF EXISTS recipe_ingredients; DROP TABLE IF EXISTS recipe_translations; DROP TABLE IF EXISTS recipes; DROP TABLE IF EXISTS dish_tags; diff --git a/backend/migrations/003_add_menu_recipe_source.sql b/backend/migrations/003_add_menu_recipe_source.sql deleted file mode 100644 index b56d805..0000000 --- a/backend/migrations/003_add_menu_recipe_source.sql +++ /dev/null @@ -1,5 +0,0 @@ --- +goose Up -ALTER TYPE recipe_source ADD VALUE IF NOT EXISTS 'menu'; - --- +goose Down --- Cannot remove enum values in PostgreSQL diff --git a/backend/migrations/004_rename_recipe_products.sql b/backend/migrations/004_rename_recipe_products.sql deleted file mode 100644 index 963f977..0000000 --- a/backend/migrations/004_rename_recipe_products.sql +++ /dev/null @@ -1,27 +0,0 @@ --- +goose Up -ALTER TABLE recipe_products RENAME TO recipe_ingredients; -ALTER INDEX idx_recipe_products_recipe_id RENAME TO idx_recipe_ingredients_recipe_id; - -ALTER TABLE recipe_ingredients - DROP CONSTRAINT recipe_products_product_id_fkey; -ALTER TABLE recipe_ingredients - RENAME COLUMN product_id TO ingredient_id; -ALTER TABLE recipe_ingredients - ADD CONSTRAINT recipe_ingredients_ingredient_id_fkey - FOREIGN KEY (ingredient_id) REFERENCES products(id) ON DELETE SET NULL; - -ALTER TABLE recipe_product_translations RENAME TO recipe_ingredient_translations; - --- +goose Down -ALTER TABLE recipe_ingredient_translations RENAME TO recipe_product_translations; - -ALTER TABLE recipe_ingredients - DROP CONSTRAINT recipe_ingredients_ingredient_id_fkey; -ALTER TABLE recipe_ingredients - RENAME COLUMN ingredient_id TO product_id; -ALTER TABLE recipe_ingredients - ADD CONSTRAINT recipe_products_product_id_fkey - FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE SET NULL; - -ALTER INDEX idx_recipe_ingredients_recipe_id RENAME TO idx_recipe_products_recipe_id; -ALTER TABLE recipe_ingredients RENAME TO recipe_products; diff --git a/backend/migrations/005_partial_menu.sql b/backend/migrations/005_partial_menu.sql deleted file mode 100644 index 00ac607..0000000 --- a/backend/migrations/005_partial_menu.sql +++ /dev/null @@ -1,12 +0,0 @@ --- +goose Up - --- Expand the meal_type check to cover all six meal types used by the client. -ALTER TABLE menu_items DROP CONSTRAINT menu_items_meal_type_check; -ALTER TABLE menu_items ADD CONSTRAINT menu_items_meal_type_check - CHECK (meal_type IN ('breakfast','second_breakfast','lunch','afternoon_snack','dinner','snack')); - --- +goose Down - -ALTER TABLE menu_items DROP CONSTRAINT menu_items_meal_type_check; -ALTER TABLE menu_items ADD CONSTRAINT menu_items_meal_type_check - CHECK (meal_type IN ('breakfast','lunch','dinner')); diff --git a/client/pubspec.lock b/client/pubspec.lock index 223b5f2..a2acdd5 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -125,10 +125,10 @@ packages: dependency: transitive description: name: characters - sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 url: "https://pub.dev" source: hosted - version: "1.4.1" + version: "1.4.0" checked_yaml: dependency: transitive description: @@ -689,26 +689,26 @@ packages: dependency: transitive description: name: matcher - sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.19" + version: "0.12.17" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.13.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.16.0" mime: dependency: transitive description: @@ -1078,10 +1078,10 @@ packages: dependency: transitive description: name: test_api - sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.10" + version: "0.7.6" typed_data: dependency: transitive description: