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
fix: allow the same contact email to exist for supplier and customer
Brad Barbin97c956570586
diff --git a/apps/erp/app/modules/purchasing/purchasing.service.ts b/apps/erp/app/modules/purchasing/purchasing.service.tsindex 3941610b29..e737ad3451 100644--- a/apps/erp/app/modules/purchasing/purchasing.service.ts+++ b/apps/erp/app/modules/purchasing/purchasing.service.ts@@ -718,7 +718,11 @@ export async function insertSupplierContact(const insertContact = await client.from("contact").insert([- { ...supplierContact.contact, companyId: supplierContact.companyId },+ {+ ...supplierContact.contact,+ companyId: supplierContact.companyId,+ isCustomer: false,+ },]).select("id").single();diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.tsindex 1965f275a3..e4a198fd9b 100644--- a/apps/erp/app/modules/sales/sales.service.ts+++ b/apps/erp/app/modules/sales/sales.service.ts@@ -1210,6 +1210,7 @@ export async function insertCustomerContact(.insert([{...customerContact.contact,+ isCustomer: true,companyId: customerContact.companyId,},])diff --git a/packages/database/supabase/migrations/20250122203100_contact-email-constraint.sql b/packages/database/supabase/migrations/20250122203100_contact-email-constraint.sqlnew file mode 100644index 0000000000..9aa56fff07--- /dev/null+++ b/packages/database/supabase/migrations/20250122203100_contact-email-constraint.sql@@ -0,0 +1,13 @@+-- Drop the unique constraint since we'll handle this via trigger+ALTER TABLE "contact"+DROP CONSTRAINT IF EXISTS "contact_email_companyId_unique";++ALTER TABLE "contact" ADD COLUMN "isCustomer" BOOLEAN NOT NULL DEFAULT TRUE;++-- Update existing supplier contacts to have isCustomer = FALSE+UPDATE "contact" c+SET "isCustomer" = FALSE+FROM "supplierContact" sc+WHERE c.id = sc."contactId";++ALTER TABLE "contact" ADD CONSTRAINT "contact_email_companyId_unique" UNIQUE ("email", "companyId", "isCustomer");