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
refactor: remove API key access for certain tables based on PR feedback
Rob Carringtonc7b924d2b9b5
diff --git a/packages/database/supabase/migrations/20240821150639_api-key-all-tables.sql b/packages/database/supabase/migrations/20240821150639_api-key-all-tables.sqlindex 21397b9757..a70fe44c33 100644--- a/packages/database/supabase/migrations/20240821150639_api-key-all-tables.sql+++ b/packages/database/supabase/migrations/20240821150639_api-key-all-tables.sql@@ -30,8 +30,6 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- attributeDataType (TODO: Ask Brad what to do for tables using auth.role() == 'authenticated', do these need an API key policy?)--- contractorCREATE POLICY "Requests with an API key can access contractors" ON "contractor"FOR ALL USING (@@ -50,7 +48,7 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- country (TODO: Ask Brad what to do for tables using auth.role() == 'authenticated', do these need an API key policy?)+-- countryALTER TABLE "country" ENABLE ROW LEVEL SECURITY;CREATE POLICY "Authenticated users can view countries" ON "country" FOR SELECT USING (auth.role() = 'authenticated');@@ -198,8 +196,6 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- customFieldTable (TODO: Ask Brad what to do for tables using auth.role() == 'authenticated', do these need an API key policy?)--- departmentCREATE POLICY "Requests with an API key can access departments" ON "department"FOR ALL USING (@@ -304,9 +300,14 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- group (TODO: identity groups don't have a companyId, also should this be settings permission?)+-- groupALTER TABLE "group" ENABLE ROW LEVEL SECURITY;+CREATE POLICY "Requests with an API key can access groups" ON "group"+FOR ALL USING (+ has_valid_api_key_for_company("companyId")+);+CREATE POLICY "Employees with settings_view can view groups" ON "group"FOR SELECT USING (has_role('employee', "companyId") AND@@ -342,8 +343,6 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- integration (TODO: Ask Brad what to do for tables using auth.role() == 'authenticated', do these need an API key policy?)--- itemCREATE POLICY "Requests with an API key can access items" ON "item"FOR ALL USING (@@ -694,33 +693,9 @@ FOR ALL USING (has_valid_api_key_for_company(get_company_id_from_foreign_key("salesOrderId", 'salesOrder')));--- salesOrderTransaction (TODO: Ask Brad if users should be able to CRUD these)+-- salesOrderTransactionALTER TABLE "salesOrderTransaction" ENABLE ROW LEVEL SECURITY;--- CREATE POLICY "Employees with sales_view can view sales order transactions" ON "salesOrderTransaction"--- FOR SELECT USING (--- has_role('employee', "companyId") AND--- has_company_permission('sales_view', "companyId")--- );---- CREATE POLICY "Employees with sales_create can create sales order transactions" ON "salesOrderTransaction"--- FOR INSERT WITH CHECK (--- has_role('employee', "companyId") AND--- has_company_permission('sales_create', "companyId")--- );---- CREATE POLICY "Employees with sales_update can update sales order transactions" ON "salesOrderTransaction"--- FOR UPDATE USING (--- has_role('employee', "companyId") AND--- has_company_permission('sales_update', "companyId")--- );---- CREATE POLICY "Employees with sales_delete can delete sales order transactions" ON "salesOrderTransaction"--- FOR DELETE USING (--- has_role('employee', "companyId") AND--- has_company_permission('sales_delete', "companyId")--- );-CREATE POLICY "Requests with an API key can access sales order transactions" ON "salesOrderTransaction"FOR ALL USING (has_valid_api_key_for_company(get_company_id_from_foreign_key("salesOrderId", 'salesOrder'))@@ -744,12 +719,6 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- search (TODO: should we exclude this from the public API?)-CREATE POLICY "Requests with an API key can access search" ON "search"-FOR ALL USING (- has_valid_api_key_for_company("companyId")-);--- sequenceALTER TABLE "sequence" ENABLE ROW LEVEL SECURITY;@@ -960,46 +929,6 @@ FOR ALL USING (has_valid_api_key_for_company("companyId"));--- user (TODO: Ask Brad for help)--- CREATE POLICY "Requests with an API key can access users" ON "user"--- FOR ALL USING (--- has_valid_api_key_for_company("companyId")--- );---- userAttribute (TODO: Ask Brad for help)--- ALTER TABLE "userAttribute" ENABLE ROW LEVEL SECURITY;---- CREATE POLICY "Requests with an API key can access user attributes" ON "userAttribute"--- FOR ALL USING (--- has_valid_api_key_for_company("companyId")--- );---- userAttributeCategory (TODO: Ask Brad for help)--- ALTER TABLE "userAttributeCategory" ENABLE ROW LEVEL SECURITY;---- CREATE POLICY "Requests with an API key can access user attribute categories" ON "userAttributeCategory"--- FOR ALL USING (--- has_valid_api_key_for_company("companyId")--- );---- userAttributeValue (TODO: Ask Brad for help)--- CREATE POLICY "Requests with an API key can access user attribute values" ON "userAttributeValue"--- FOR ALL USING (--- has_valid_api_key_for_company(get_company_id_from_foreign_key("userAttributeId", 'userAttribute'))--- );---- userPermissions (TODO: Ask Brad for help)--- CREATE POLICY "Requests with an API key can access user premissions" ON "userPermissions"--- FOR ALL USING (--- has_valid_api_key_for_company("companyId")--- );---- userToCompany (TODO: Ask Brad for help - should we exclude this from the public API?)--- CREATE POLICY "Requests with an API key can access user to company mapping" ON "userToCompany"--- FOR ALL USING (--- has_valid_api_key_for_company("companyId")--- );--- warehouseCREATE POLICY "Requests with an API key can access warehouses" ON "warehouse"FOR ALL USING (