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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user