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: readable id function

Brad Barbin0dd1864cf131
diff --git a/packages/database/supabase/migrations/20250923225147_uuid-ship-fix.sql b/packages/database/supabase/migrations/20250923225147_uuid-ship-fix.sql
new file mode 100644
index 0000000000..60e973bd2c
--- /dev/null
+++ b/packages/database/supabase/migrations/20250923225147_uuid-ship-fix.sql
@@ -0,0 +1,19 @@
+CREATE OR REPLACE FUNCTION id(_prefix TEXT DEFAULT NULL)
+ RETURNS TEXT
+ LANGUAGE plpgsql
+AS
+$$
+DECLARE
+ _uuid TEXT;
+BEGIN
+ -- Generate UUID v4 and remove hyphens
+ _uuid := REPLACE(uuid_to_base58(extensions.uuid_generate_v4()), '-', '');
+
+ -- If prefix is provided, prepend it with underscore
+ IF _prefix IS NOT NULL THEN
+ RETURN _prefix || '_' || _uuid;
+ ELSE
+ RETURN _uuid;
+ END IF;
+END;
+$$;
\ No newline at end of file