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


-- 流程节点表
CREATE TABLE public.plan_process_steps (
 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 plan_id UUID NOT NULL REFERENCES public.production_plans(id) ON DELETE CASCADE,
 step_type public.step_type NOT NULL,
 status public.step_status NOT NULL DEFAULT 'pending',
 timestamp TIMESTAMPTZ,
 operator_id UUID REFERENCES auth.users(id) ON DELETE SET NULL,
 notes TEXT,
 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 结款记录表
CREATE TABLE public.payments (
 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 plan_id UUID NOT NULL REFERENCES public.production_plans(id) ON DELETE CASCADE,
 from_company_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE,
 to_company_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE,
 amount DECIMAL NOT NULL DEFAULT 0,
 quantity DECIMAL NOT NULL DEFAULT 0,
 price_per_meter DECIMAL NOT NULL DEFAULT 0,
 status public.payment_status NOT NULL DEFAULT 'pending',
 paid_at TIMESTAMPTZ,
 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

