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

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