Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
-- Drop unused approverId column from approvalRequest table
-- The approval system uses approverGroupIds on approval rules to determine who can approve,
-- and records the actual decision maker in decisionBy.
-- Drop the view first since it depends on approverId
DROP VIEW IF EXISTS "approvalRequests";
ALTER TABLE "approvalRequest" DROP CONSTRAINT "approvalRequest_approverId_fkey";
DROP INDEX "approvalRequest_approverId_idx";
ALTER TABLE "approvalRequest" DROP COLUMN "approverId";
-- Recreate the view without approverId
CREATE OR REPLACE VIEW "approvalRequests" WITH (SECURITY_INVOKER=true) AS
SELECT
ar."id",
ar."documentType",
ar."documentId",
ar."status",
ar."requestedBy",
ar."requestedAt",
ar."decisionBy",
ar."decisionAt",
ar."decisionNotes",
ar."companyId",
ar."createdAt",
CASE
WHEN ar."documentType" = 'purchaseOrder' THEN po."purchaseOrderId"
WHEN ar."documentType" = 'qualityDocument' THEN qd."name"
ELSE NULL
END AS "documentReadableId",
CASE
WHEN ar."documentType" = 'purchaseOrder' THEN s."name"
WHEN ar."documentType" = 'qualityDocument' THEN qd."description"
ELSE NULL
END AS "documentDescription"
FROM "approvalRequest" ar
LEFT JOIN "purchaseOrder" po ON ar."documentType" = 'purchaseOrder' AND ar."documentId" = po."id"
LEFT JOIN "supplier" s ON po."supplierId" = s."id"
LEFT JOIN "qualityDocument" qd ON ar."documentType" = 'qualityDocument' AND ar."documentId" = qd."id";