-- +goose Up

CREATE TABLE meal_diary (
    id         UUID PRIMARY KEY DEFAULT uuid_generate_v7(),
    user_id    UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    date       DATE NOT NULL,
    meal_type  TEXT NOT NULL,
    name       TEXT NOT NULL,
    portions   DECIMAL(5,2) NOT NULL DEFAULT 1,
    calories   DECIMAL(8,2),
    protein_g  DECIMAL(8,2),
    fat_g      DECIMAL(8,2),
    carbs_g    DECIMAL(8,2),
    source     TEXT NOT NULL DEFAULT 'manual',
    recipe_id  UUID REFERENCES saved_recipes(id) ON DELETE SET NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_meal_diary_user_date ON meal_diary(user_id, date);

-- +goose Down
DROP TABLE meal_diary;
