-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "AdmissionPackageId";

ALTER TABLE IF EXISTS public."ServiceOrder"
    ADD COLUMN "AdmissionPackageId" integer;

-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "PackageModuleDetailId";

ALTER TABLE IF EXISTS public."ServiceOrder"
    ADD COLUMN "PackageModuleDetailId" integer;

-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "UsedQuantity";

ALTER TABLE IF EXISTS public."ServiceOrder"
    ADD COLUMN "UsedQuantity" integer;

-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "UsedCost";

ALTER TABLE IF EXISTS public."ServiceOrder"
    ADD COLUMN "UsedCost" numeric(10,2);

-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP CONSTRAINT IF EXISTS "FK_ServiceOrder_AdmissionPackageId";

ALTER TABLE IF EXISTS public."ServiceOrder"
    ADD CONSTRAINT "FK_ServiceOrder_AdmissionPackageId" FOREIGN KEY ("AdmissionPackageId")
    REFERENCES public."AdmissionPackage" ("AdmissionPackageId") MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;

-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP CONSTRAINT IF EXISTS "FK_ServiceOrder_PackageModuleDetailId";

ALTER TABLE IF EXISTS public."ServiceOrder"
    ADD CONSTRAINT "FK_ServiceOrder_PackageModuleDetailId" FOREIGN KEY ("PackageModuleDetailId")
    REFERENCES public."PackageModuleDetail" ("PackageModuleDetailId") MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;