sozsoft-platform/configs/seeds/postgres/object/Prc_T_MaterialRequestLine.sql

35 lines
1.5 KiB
MySQL
Raw Normal View History

2026-10-09 17:02:27 +00:00
CREATE TABLE IF NOT EXISTS public."Prc_T_MaterialRequestLine"
(
"Id" uuid NOT NULL DEFAULT gen_random_uuid(),
"TenantId" uuid NULL,
"MaterialRequestId" uuid NOT NULL,
"ProductId" uuid NOT NULL,
"Quantity" numeric(18, 4) NOT NULL,
"UomId" uuid NOT NULL,
"FulfillmentMethod" varchar(16) NOT NULL DEFAULT 'Purchase',
"DueDate" date NOT NULL,
"RequestReason" varchar(256) NOT NULL,
"DeliveredQuantity" numeric(18, 4) NOT NULL DEFAULT 0,
"PlannedQuantity" numeric(18, 4) NULL,
"PurchaseResponsibleUserId" uuid NULL,
"LineStatus" varchar(16) NOT NULL DEFAULT 'Waiting',
"CreationTime" timestamp NOT NULL DEFAULT (NOW() AT TIME ZONE 'UTC'),
"CreatorId" uuid NULL,
"LastModificationTime" timestamp NULL,
"LastModifierId" uuid NULL,
"IsDeleted" boolean NOT NULL DEFAULT FALSE,
"DeletionTime" timestamp NULL,
"DeleterId" uuid NULL,
CONSTRAINT "PK_Prc_T_MaterialRequestLine" PRIMARY KEY ("Id")
);
CREATE INDEX IF NOT EXISTS "IX_Prc_T_MaterialRequestLine_MaterialRequestId" ON public."Prc_T_MaterialRequestLine" ("MaterialRequestId");
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_Prc_T_MaterialRequestLine_MaterialRequestId') THEN
ALTER TABLE public."Prc_T_MaterialRequestLine" ADD CONSTRAINT "FK_Prc_T_MaterialRequestLine_MaterialRequestId" FOREIGN KEY ("MaterialRequestId") REFERENCES public."Prc_T_MaterialRequest" ("Id") ON DELETE CASCADE ON UPDATE NO ACTION;
END IF;
END
$$;