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.
paths: - "apps/erp/app/modules/quality/ui/RiskRegister/**" - "apps/erp/app/routes/x+/quality+/risks*.tsx" - "packages/database/supabase/migrations/risk.sql"
Risk Register Module (Quality)
Tracks risks and opportunities tied to entities across Carbon (items, jobs,
customers, suppliers, work centers, quote lines, or general). Part of the
quality module — code lives under apps/erp/app/modules/quality/. Schema is
grounded in the migrations; newest wins.
Schema — riskRegister table
Created 20251210060100_add-risk-registers.sql, then evolved by three later
migrations (read the newest before trusting columns):
20251218024157_risk-register-improvements.sql— addedtype "riskRegisterType"(NOT NULL DEFAULT'Risk') andnotes JSON(DEFAULT'{}').20260102015412_risk-registers-view.sql— created theriskRegistersview.20260323184848_add_updatedby_riskregister.sql— addedupdatedBy(FK →user).
Columns: id UUID PK (gen_random_uuid() — not the usual id('prefix')),
companyId, title (required), description, source "riskSource" (required),
sourceId TEXT (id of the associated entity, generic), severity INTEGER
(CHECK 1–5), likelihood INTEGER (CHECK 1–5), itemId TEXT (FK → item,
ON DELETE SET NULL — a dedicated column, separate from sourceId),
status "riskStatus" (default 'Open'), type "riskRegisterType" (default
'Risk'), notes JSON, assignee/createdBy/updatedBy (FK → user),
createdAt, updatedAt.
There is NO
scorecolumn. Severity and likelihood are stored independently; nothing computes or persistsseverity × likelihood. (The old cache claimed ascorecolumn and an auto-calc — both are wrong.)
PK is just ("id") (single-column UUID), not the usual composite (id, companyId).
Indexes: companyId, assignee, itemId, status, source, and (type, companyId).
Enums (title-cased — match exactly; old cache had wrong UPPER_SNAKE values)
riskSource:Customer,General,Item,Job,Quote Line,Supplier,Work Center. (No*_MASTERvariants — those never existed.)riskStatus:Open,In Review,Mitigating,Closed,Accepted.riskRegisterType:Risk,Opportunity.
Mirrored as as const arrays in quality.models.ts (riskSource, riskStatus,
riskRegisterType).
riskRegisters view
SECURITY_INVOKER=on. Selects riskRegister.* plus workCenterName/workCenterId
via LEFT JOIN "workCenter" wc ON r."sourceId" = wc."id". getRisks (the list
query) reads this view; getRisk and the per-entity cards read the base
riskRegister table.
RLS
SELECT/INSERT → any company employee (get_companies_with_employee_role()).
UPDATE → quality_update; DELETE → quality_delete.
Workflow & scoring
- Severity and likelihood are two independent 1–5 ratings, rendered by
RiskRating.tsxas N colored bars (1–2 emerald, 3 yellow, 4 orange, 5 red). There is no combined score anywhere — UI shows the two ratings side by side. - Status is a free-set enum (
Open→In Review→Mitigating→Closed/Accepted);updateRiskStatus(client, riskId, status)patches it. No state-machine enforcement. createRisk(quality.server.ts; routerisks.new.tsxparsesseverity/likelihoodfrom strings to ints) defaultsassigneeto the current user and fires anotifyjob (NotificationEvent.RiskAssignment) when an assignee is set.updateRisk(risks.$id.tsx) notifies a new assignee.upsertRiskis the bare row write and is not published.
Code map (verified)
- Service
apps/erp/app/modules/quality/quality.service.ts:getRisk,getRisks(readsriskRegistersview, filtersstatus/source/assignee, search on title/description, generic filters sortedcreatedAtdesc),upsertRisk(id present → update +updatedBy/updatedAt; else insert — does NOT compute a score),updateRiskStatus,deleteRisk. - Validators
quality.models.ts:riskRegisterValidator(severity/likelihoodare required strings min-1;notesparsed from JSON string; includesitemId,sourceId,type). - UI
ui/RiskRegister/:RiskRegisterForm.tsx(drawer form),RiskRegistersTable.tsx(global list),RiskRegisterCard.tsx(per-entity card, queriesriskRegisterfiltered bysource+sourceId),RiskRating.tsx,RiskStatus.tsx,RiskType.tsx. - Routes
apps/erp/app/routes/x+/quality+/:risks.tsx(list,view: "quality"),risks.new.tsx(createRisk: company membership, and the table's employee-only INSERT policy — notcreate: "quality"; not published),risks.$id.tsx(loaderview,updateRisk:update: "quality"),risks.delete.$id.tsx(delete: "quality"). - Path helpers (
apps/erp/app/utils/path.ts):risks,risk(id),newRisk,deleteRisk(id), pluscustomerRisks(id)/supplierRisks(id).
Entity integration
Per-entity cards wrap RiskRegisterCard with a fixed source and pass the entity id
as sourceId:
- Items →
ItemRiskRegister.tsx(source="Item", also passesitemId) — used on part/material/tool/consumable detail pages. - Customer →
modules/sales/ui/Customer/CustomerRiskRegister.tsx(source="Customer"), routex+/customer+/$customerId.risks.tsx. - Supplier →
modules/purchasing/ui/Supplier/SupplierRiskRegister.tsx(source="Supplier"), routex+/supplier+/$supplierId.risks.tsx.
Cards filter on source AND sourceId. Items additionally populate the dedicated
itemId FK column (in addition to sourceId). Two more entity cards exist:
- Job →
modules/production/ui/Jobs/JobRiskRegister.tsx(source="Job", also passesitemId). - Quote Line →
modules/sales/ui/Quotes/QuoteLineRiskRegister.tsx(source="Quote Line").
The riskSource enum (quality.models.ts) is
Customer | General | Item | Job | Quote Line | Supplier | Work Center. All have a
wired-up entity card except Work Center, which is surfaced only via the
riskRegisters view join (no dedicated card/route).
Gotchas
- No score. Don't reintroduce a
scorecolumn or aseverity × likelihoodcalc — the design keeps the two ratings separate. - Enums are title-cased (
Open,Item,Work Center), not UPPER_SNAKE. getRisksreads theriskRegistersview (forworkCenterName); single-row and per-entity reads use theriskRegistertable. Keep that split in mind.riskRegisterPK is a single UUIDid, and the default isgen_random_uuid()— it deviates from the standardid('prefix')+ composite-PK table template.- Creating a risk only requires being an employee (RLS); editing/deleting require
quality_update/quality_delete.