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: make the legacy private bucket read-only and re-run the company bucket copy (#1810)

Anshul sharma6ca1ec951c89
diff --git a/packages/database/supabase/migrations/20261002022403_private-bucket-read-only.sql b/packages/database/supabase/migrations/20261002022403_private-bucket-read-only.sql
new file mode 100644
index 0000000000..af56715527
--- /dev/null
+++ b/packages/database/supabase/migrations/20261002022403_private-bucket-read-only.sql
@@ -0,0 +1,4 @@
+-- The legacy shared `private` bucket stays readable and deletable but takes no
+-- new files: no row may be written into it. An UPDATE that moves a file out to
+-- the caller's own company bucket still passes "Company bucket access".
+ALTER POLICY "Shared Private Bucket" ON storage.objects WITH CHECK (false);
diff --git a/scripts/one-off/recopy-private-buckets.ts b/scripts/one-off/recopy-private-buckets.ts
new file mode 100644
index 0000000000..a64a253971
--- /dev/null
+++ b/scripts/one-off/recopy-private-buckets.ts
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+// Second pass of migrate-private-buckets.ts. The first pass ran while the
+// legacy `private` bucket was still writable, so files written there after it
+// exist only in `private`. 20261002022403_private-bucket-read-only.sql closes the
+// bucket to sessions and API keys in the same deploy, before this runs. The
+// service role bypasses that policy, so this pass is final only while no
+// service-role code writes to `private`.
+//
+// Same copy, new ledger name: the script is idempotent and skips objects that
+// are already in the company bucket.
+//
+// Safe to remove once every deployment has run it.
+import "./migrate-private-buckets";