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
-- Generated by `pnpm --filter @carbon/database authz migration` from packages/database/src/authz. Do not edit.
-- Ships these rules to databases where `authz sync` does not run after migrations yet.
CREATE OR REPLACE FUNCTION public.sync_unload_work_center_operation(p_table text, p_operation text, p_new jsonb, p_old jsonb)
RETURNS void
LANGUAGE plpgsql
SET search_path TO 'public'
AS $function$
BEGIN
-- A deleted operation unloads too: the pointer has no foreign key, because
-- one would make PostgREST embeds of workCenter from jobOperation ambiguous.
IF p_operation = 'DELETE' THEN
UPDATE "workCenter"
SET "loadedJobOperationId" = NULL,
"loadedAt" = NULL
WHERE "loadedJobOperationId" = p_old->>'id';
RETURN;
END IF;
IF p_operation != 'UPDATE' THEN RETURN; END IF;
IF (p_new->>'status') NOT IN ('Done', 'Canceled') THEN RETURN; END IF;
IF (p_old->>'status') = (p_new->>'status') THEN RETURN; END IF;
UPDATE "workCenter"
SET "loadedJobOperationId" = NULL,
"loadedAt" = NULL
WHERE "loadedJobOperationId" = p_new->>'id';
END;
$function$;