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.

feat: set metric setting based on base currency/country

Brad Barbinf4422125a2dc
diff --git a/packages/database/supabase/migrations/20250725212215_metric-default.sql b/packages/database/supabase/migrations/20250725212215_metric-default.sql
new file mode 100644
index 0000000000..c6d8b2f052
--- /dev/null
+++ b/packages/database/supabase/migrations/20250725212215_metric-default.sql
@@ -0,0 +1,30 @@
+-- Create new function to insert both terms and settings
+CREATE OR REPLACE FUNCTION insert_company_related_records()
+RETURNS TRIGGER AS $$
+BEGIN
+ -- Insert terms record
+ INSERT INTO "terms" ("id")
+ VALUES (NEW.id);
+
+ -- Insert company settings record with metric setting based on country/currency
+ INSERT INTO "companySettings" ("id", "useMetric")
+ VALUES (
+ NEW.id,
+ CASE
+ WHEN NEW."countryCode" = 'US' OR NEW."baseCurrencyCode" = 'USD' THEN false
+ ELSE true
+ END
+ );
+
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql;
+
+-- Update useMetric setting for all existing companies
+UPDATE "companySettings"
+SET "useMetric" = CASE
+ WHEN c."countryCode" = 'US' OR c."baseCurrencyCode" = 'USD' THEN false
+ ELSE true
+END
+FROM "company" c
+WHERE "companySettings"."id" = c."id";