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: don't delete payments or shipments when customer is deleted

Brad Barbinbb35600eae00
diff --git a/packages/database/supabase/migrations/20250315111612_shipment-payment-customer-delete.sql b/packages/database/supabase/migrations/20250315111612_shipment-payment-customer-delete.sql
new file mode 100644
index 0000000000..7921ae6e30
--- /dev/null
+++ b/packages/database/supabase/migrations/20250315111612_shipment-payment-customer-delete.sql
@@ -0,0 +1,25 @@
+
+
+-- Update quote foreign key constraints for customer
+ALTER TABLE "quote" DROP CONSTRAINT "quote_customerId_fkey";
+ALTER TABLE "quote" ADD CONSTRAINT "quote_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customer"("id") ON DELETE SET NULL;
+
+-- Update quotePayment foreign key constraints for customer
+ALTER TABLE "quotePayment" DROP CONSTRAINT "quotePayment_invoiceCustomerId_fkey";
+ALTER TABLE "quotePayment" ADD CONSTRAINT "quotePayment_invoiceCustomerId_fkey" FOREIGN KEY ("invoiceCustomerId") REFERENCES "customer"("id") ON DELETE SET NULL;
+
+-- Update salesOrder foreign key constraints for customer
+ALTER TABLE "salesOrder" DROP CONSTRAINT "salesOrder_customerId_fkey";
+ALTER TABLE "salesOrder" ADD CONSTRAINT "salesOrder_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customer"("id") ON DELETE SET NULL;
+
+-- Update salesOrderPayment foreign key constraints for customer
+ALTER TABLE "salesOrderPayment" DROP CONSTRAINT "salesOrderPayment_invoiceCustomerId_fkey";
+ALTER TABLE "salesOrderPayment" ADD CONSTRAINT "salesOrderPayment_invoiceCustomerId_fkey" FOREIGN KEY ("invoiceCustomerId") REFERENCES "customer"("id") ON DELETE SET NULL;
+
+-- Update purchaseOrder foreign key constraints for supplier
+ALTER TABLE "purchaseOrder" DROP CONSTRAINT "purchaseOrder_supplierId_fkey";
+ALTER TABLE "purchaseOrder" ADD CONSTRAINT "purchaseOrder_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES "supplier"("id") ON DELETE SET NULL;
+
+-- Update purchaseOrderPayment foreign key constraints for supplier
+ALTER TABLE "purchaseOrderPayment" DROP CONSTRAINT "purchaseOrderPayment_invoiceSupplierId_fkey";
+ALTER TABLE "purchaseOrderPayment" ADD CONSTRAINT "purchaseOrderPayment_invoiceSupplierId_fkey" FOREIGN KEY ("invoiceSupplierId") REFERENCES "supplier"("id") ON DELETE SET NULL;
\ No newline at end of file