-- +goose Up CREATE TABLE products ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, mapping_id UUID REFERENCES ingredient_mappings(id), name TEXT NOT NULL, quantity DECIMAL(10, 2) NOT NULL DEFAULT 1, unit TEXT NOT NULL DEFAULT 'pcs', category TEXT, storage_days INT NOT NULL DEFAULT 7, added_at TIMESTAMPTZ NOT NULL DEFAULT now(), expires_at TIMESTAMPTZ GENERATED ALWAYS AS (added_at + (storage_days || ' days')::INTERVAL) STORED ); CREATE INDEX idx_products_user_id ON products(user_id); CREATE INDEX idx_products_expires_at ON products(user_id, expires_at); -- +goose Down DROP TABLE products;