chore: squash migrations 003–005 into 001_initial_schema

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 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-22 21:52:26 +02:00
parent 9580bff54e
commit edf587e798
5 changed files with 27 additions and 71 deletions

View File

@@ -48,7 +48,7 @@ CREATE TYPE user_plan AS ENUM ('free', 'paid');
CREATE TYPE user_gender AS ENUM ('male', 'female'); CREATE TYPE user_gender AS ENUM ('male', 'female');
CREATE TYPE user_goal AS ENUM ('lose', 'maintain', 'gain'); CREATE TYPE user_goal AS ENUM ('lose', 'maintain', 'gain');
CREATE TYPE activity_level AS ENUM ('low', 'moderate', 'high'); 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'); 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 ( CREATE TABLE recipe_ingredients (
id UUID PRIMARY KEY DEFAULT uuid_generate_v7(), id UUID PRIMARY KEY DEFAULT uuid_generate_v7(),
recipe_id UUID NOT NULL REFERENCES recipes(id) ON DELETE CASCADE, recipe_id UUID NOT NULL REFERENCES recipes(id) ON DELETE CASCADE,
product_id UUID REFERENCES products(id) ON DELETE SET NULL, ingredient_id UUID REFERENCES products(id) ON DELETE SET NULL,
name TEXT NOT NULL, name TEXT NOT NULL,
amount DECIMAL(10,2) NOT NULL DEFAULT 0, amount DECIMAL(10,2) NOT NULL DEFAULT 0,
unit_code VARCHAR(20), unit_code VARCHAR(20),
is_optional BOOLEAN NOT NULL DEFAULT false, is_optional BOOLEAN NOT NULL DEFAULT false,
sort_order SMALLINT NOT NULL DEFAULT 0 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 ( CREATE TABLE recipe_ingredient_translations (
ri_id UUID NOT NULL REFERENCES recipe_products(id) ON DELETE CASCADE, ri_id UUID NOT NULL REFERENCES recipe_ingredients(id) ON DELETE CASCADE,
lang VARCHAR(10) NOT NULL, lang VARCHAR(10) NOT NULL,
name TEXT NOT NULL, name TEXT NOT NULL,
PRIMARY KEY (ri_id, lang) PRIMARY KEY (ri_id, lang)
@@ -372,7 +372,7 @@ CREATE TABLE menu_items (
id UUID PRIMARY KEY DEFAULT uuid_generate_v7(), id UUID PRIMARY KEY DEFAULT uuid_generate_v7(),
menu_plan_id UUID NOT NULL REFERENCES menu_plans(id) ON DELETE CASCADE, 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), 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, recipe_id UUID REFERENCES recipes(id) ON DELETE SET NULL,
dish_id UUID REFERENCES dishes(id) ON DELETE SET NULL, dish_id UUID REFERENCES dishes(id) ON DELETE SET NULL,
recipe_data JSONB, recipe_data JSONB,
@@ -621,8 +621,8 @@ DROP TABLE IF EXISTS user_product_components;
DROP TABLE IF EXISTS user_products; DROP TABLE IF EXISTS user_products;
DROP TABLE IF EXISTS recipe_step_translations; DROP TABLE IF EXISTS recipe_step_translations;
DROP TABLE IF EXISTS recipe_steps; DROP TABLE IF EXISTS recipe_steps;
DROP TABLE IF EXISTS recipe_product_translations; DROP TABLE IF EXISTS recipe_ingredient_translations;
DROP TABLE IF EXISTS recipe_products; DROP TABLE IF EXISTS recipe_ingredients;
DROP TABLE IF EXISTS recipe_translations; DROP TABLE IF EXISTS recipe_translations;
DROP TABLE IF EXISTS recipes; DROP TABLE IF EXISTS recipes;
DROP TABLE IF EXISTS dish_tags; DROP TABLE IF EXISTS dish_tags;

View File

@@ -1,5 +0,0 @@
-- +goose Up
ALTER TYPE recipe_source ADD VALUE IF NOT EXISTS 'menu';
-- +goose Down
-- Cannot remove enum values in PostgreSQL

View File

@@ -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;

View File

@@ -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'));

View File

@@ -125,10 +125,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.4.1" version: "1.4.0"
checked_yaml: checked_yaml:
dependency: transitive dependency: transitive
description: description:
@@ -689,26 +689,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.19" version: "0.12.17"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.13.0" version: "0.11.1"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.17.0" version: "1.16.0"
mime: mime:
dependency: transitive dependency: transitive
description: description:
@@ -1078,10 +1078,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.10" version: "0.7.6"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description: