Files
threadcount-community/prisma/migrations/20260828160000_issue_cost_backorder_parent/migration.sql
T
ThreadCount a6f1059ddf ThreadCount Community edition
Uniform stock management for healthcare linen rooms: the coordinator app, the phone counter and the staff app, for your own server. Built from a113353 on 2026-09-15. Licensed under the Functional Source License (FSL-1.1-ALv2).
2026-09-15 22:54:09 +10:00

14 lines
812 B
SQL

-- Cost at time of issue (backfilled from the current catalogue price for existing rows)
ALTER TABLE "Issue" ADD COLUMN "cost" DOUBLE PRECISION NOT NULL DEFAULT 0;
UPDATE "Issue" i SET "cost" = c."cost" FROM "CatalogItem" c WHERE c."id" = i."itemId";
-- Back orders link to their parent order
ALTER TABLE "Order" ADD COLUMN "parentId" TEXT;
ALTER TABLE "Order" ADD CONSTRAINT "Order_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Order"("id") ON DELETE SET NULL ON UPDATE CASCADE;
UPDATE "Order" b SET "parentId" = p."id"
FROM "Order" p
WHERE b."parentId" IS NULL AND b."status" IN ('Back Order','Received','Cancelled','Shipped','Ordered')
AND b."notes" LIKE 'Back order — short on ORD-%'
AND p."facilityId" = b."facilityId"
AND p."code" = substring(b."notes" from 'short on (ORD-[0-9]+-[0-9]+)');