Skip to content

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.

fix: backfill missing operation id on job materials

Brad Barbinff946878cd32
diff --git a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx
index 3476b14198..a5d65b5043 100644
--- a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx
@@ -44,7 +44,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
if (line.error) {
throw redirect(
- path.to.quote(rfqId),
+ path.to.salesRfq(rfqId),
await flash(request, error(line.error, "Failed to load line"))
);
}
diff --git a/packages/database/supabase/migrations/20260120132502_backfill-operation-id-for-job-materials.sql b/packages/database/supabase/migrations/20260120132502_backfill-operation-id-for-job-materials.sql
new file mode 100644
index 0000000000..c7047957bd
--- /dev/null
+++ b/packages/database/supabase/migrations/20260120132502_backfill-operation-id-for-job-materials.sql
@@ -0,0 +1,18 @@
+-- Backfill jobOperationId for job materials that are missing it
+-- Logic: Assign each material to the first operation (by order) with the same jobMakeMethodId
+WITH first_operations AS (
+ SELECT DISTINCT ON ("jobMakeMethodId")
+ "id" as "operationId",
+ "jobMakeMethodId"
+ FROM "jobOperation"
+ WHERE "jobMakeMethodId" IS NOT NULL
+ ORDER BY "jobMakeMethodId", "order" ASC
+)
+UPDATE "jobMaterial" jm
+SET "jobOperationId" = fo."operationId"
+FROM first_operations fo, "job" j
+WHERE
+ jm."jobMakeMethodId" = fo."jobMakeMethodId"
+ AND jm."jobId" = j."id"
+ AND jm."jobOperationId" IS NULL
+ AND j."status" != 'Draft';