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


-- 仓库表
CREATE TABLE public.warehouses (
 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 company_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE,
 name TEXT NOT NULL,
 type public.warehouse_type NOT NULL,
 location TEXT,
 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 入库记录表
CREATE TABLE public.inventory_records (
 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 plan_id UUID NOT NULL REFERENCES public.production_plans(id) ON DELETE CASCADE,
 warehouse_id UUID NOT NULL REFERENCES public.warehouses(id) ON DELETE CASCADE,
 quantity DECIMAL NOT NULL DEFAULT 0,
 warehouse_location TEXT,
 operator_id UUID REFERENCES auth.users(id) ON DELETE SET NULL,
 created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 纱线库存表
CREATE TABLE public.yarn_stock (
 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 company_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE,
 warehouse_id UUID REFERENCES public.warehouses(id) ON DELETE SET NULL,
 name TEXT NOT NULL,
 spec TEXT,
 quantity DECIMAL NOT NULL DEFAULT 0,
 min_stock DECIMAL NOT NULL DEFAULT 0,
 unit TEXT NOT NULL DEFAULT 'kg',
 updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

