sozsoft-platform/configs/seeds/postgres/object/Stk_T_Transfer.sql
2026-10-19 17:35:08 +03:00

79 lines
3.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Envanter hareket belgesi: Alım, Teslimat, İç Transfer (ve sonra Üretim) aynı başlık tablosunu paylaşır; tür OperationKind ile ayrılır.
CREATE TABLE IF NOT EXISTS public."Stk_T_Transfer"
(
"Id" uuid NOT NULL DEFAULT gen_random_uuid(),
"TenantId" uuid NULL,
"TransferNo" varchar(32) NULL,
"BranchId" uuid NOT NULL,
"WarehouseId" uuid NOT NULL,
"OperationTypeId" uuid NOT NULL,
"OperationKind" varchar(32) NOT NULL DEFAULT 'Receipt',
"PartnerId" uuid NULL,
"SourceLocationId" uuid NULL,
"DestinationLocationId" uuid NULL,
"ScheduledDate" timestamp NOT NULL DEFAULT (NOW() AT TIME ZONE 'UTC'),
"EffectiveDate" timestamp NULL,
"SourceDocument" varchar(128) NULL,
"PurchaseOrderId" uuid NULL,
"BackorderOfId" uuid NULL,
"ReturnOfId" uuid NULL,
"CarrierId" uuid NULL,
"TrackingReference" varchar(128) NULL,
"Weight" numeric(18, 4) NOT NULL DEFAULT 0,
"ShippingWeight" numeric(18, 4) NOT NULL DEFAULT 0,
"ResponsibleUserId" uuid NULL,
"ProjectId" uuid NULL,
"DeliveryPolicy" varchar(16) NULL,
"Note" text NULL,
"LineSummary" text NULL,
"Status" varchar(16) NOT NULL DEFAULT 'Draft',
"PendingAction" varchar(16) NULL,
"ReceivedByUserId" uuid NULL,
"ReceivedDate" timestamp NULL,
"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_Stk_T_Transfer" PRIMARY KEY ("Id")
);
CREATE INDEX IF NOT EXISTS "IX_Stk_T_Transfer_TenantId_OperationKind_Status" ON public."Stk_T_Transfer" ("TenantId", "OperationKind", "Status");
CREATE INDEX IF NOT EXISTS "IX_Stk_T_Transfer_OperationTypeId" ON public."Stk_T_Transfer" ("OperationTypeId");
CREATE INDEX IF NOT EXISTS "IX_Stk_T_Transfer_PurchaseOrderId" ON public."Stk_T_Transfer" ("PurchaseOrderId");
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_Stk_T_Transfer_BranchId') THEN
ALTER TABLE public."Stk_T_Transfer" ADD CONSTRAINT "FK_Stk_T_Transfer_BranchId" FOREIGN KEY ("BranchId") REFERENCES public."Sas_T_Branch" ("Id") ON DELETE NO ACTION ON UPDATE NO ACTION;
END IF;
END
$$;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_Stk_T_Transfer_OperationTypeId') THEN
ALTER TABLE public."Stk_T_Transfer" ADD CONSTRAINT "FK_Stk_T_Transfer_OperationTypeId" FOREIGN KEY ("OperationTypeId") REFERENCES public."Stk_T_OperationType" ("Id") ON DELETE NO ACTION ON UPDATE NO ACTION;
END IF;
END
$$;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_Stk_T_Transfer_SourceLocationId') THEN
ALTER TABLE public."Stk_T_Transfer" ADD CONSTRAINT "FK_Stk_T_Transfer_SourceLocationId" FOREIGN KEY ("SourceLocationId") REFERENCES public."Stk_T_Location" ("Id") ON DELETE NO ACTION ON UPDATE NO ACTION;
END IF;
END
$$;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_Stk_T_Transfer_DestinationLocationId') THEN
ALTER TABLE public."Stk_T_Transfer" ADD CONSTRAINT "FK_Stk_T_Transfer_DestinationLocationId" FOREIGN KEY ("DestinationLocationId") REFERENCES public."Stk_T_Location" ("Id") ON DELETE NO ACTION ON UPDATE NO ACTION;
END IF;
END
$$;