-- ============================================
-- 此文件由 Meoo Cloud 自动生成，请勿修改
-- This file is auto-generated by Meoo Cloud, DO NOT MODIFY
-- ============================================

CREATE TABLE public.product_price_history (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), product_id UUID NOT NULL REFERENCES public.products(id) ON DELETE CASCADE, company_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, old_price DECIMAL NOT NULL DEFAULT 0, new_price DECIMAL NOT NULL DEFAULT 0, change_amount DECIMAL NOT NULL DEFAULT 0, operator_id UUID REFERENCES auth.users(id) ON DELETE SET NULL, operator_name TEXT, change_reason TEXT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()); CREATE INDEX idx_product_price_history_product ON public.product_price_history(product_id); CREATE INDEX idx_product_price_history_company ON public.product_price_history(company_id); CREATE INDEX idx_product_price_history_created ON public.product_price_history(created_at); ALTER TABLE public.product_price_history ENABLE ROW LEVEL SECURITY; CREATE POLICY company_select_price_history ON public.product_price_history FOR SELECT USING (company_id = get_user_master_company_id()); CREATE POLICY company_insert_price_history ON public.product_price_history FOR INSERT WITH CHECK (company_id = get_user_master_company_id());
