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
fix: add rls to scrap reasons and pre-populate existing companies
Brad Barbin3259906cf5a5
diff --git a/packages/database/supabase/functions/lib/seed.ts b/packages/database/supabase/functions/lib/seed.tsindex f609411ce3..37ec2230b8 100644--- a/packages/database/supabase/functions/lib/seed.ts+++ b/packages/database/supabase/functions/lib/seed.ts@@ -1677,7 +1677,7 @@ export const postingGroupSales = {updatedBy: "system",};-export const scrapReasons = ["Defective", "Damaged", "Quality Control"];+export const scrapReasons = ["Defective", "Damaged", "Quality"];export const sequences = [{diff --git a/packages/database/supabase/migrations/20241028205306_prepopulate-scrap-reasons.sql b/packages/database/supabase/migrations/20241028205306_prepopulate-scrap-reasons.sqlnew file mode 100644index 0000000000..07dae370c7--- /dev/null+++ b/packages/database/supabase/migrations/20241028205306_prepopulate-scrap-reasons.sql@@ -0,0 +1,44 @@+DO $$+DECLARE+ company_record RECORD;+ scrap_reason TEXT;+BEGIN+ FOR company_record IN SELECT id FROM companies LOOP+ FOR scrap_reason IN SELECT unnest(ARRAY['Defective', 'Damaged', 'Quality']) LOOP+ INSERT INTO "scrapReason" ("companyId", name)+ VALUES (company_record.id, scrap_reason);+ END LOOP;+ END LOOP;+END $$;++ALTER TABLE "scrapReason" ENABLE ROW LEVEL SECURITY;++CREATE POLICY "Employees can view scrap reasons" ON "scrapReason"+ FOR SELECT+ USING (+ has_role('employee', "companyId") AND+ "companyId" = ANY(+ select "companyId" from "userToCompany" where "userId" = auth.uid()::text+ )+ );++CREATE POLICY "Employees with production_create can insert scrap reasons" ON "scrapReason"+ FOR INSERT+ WITH CHECK (+ has_role('employee', "companyId") AND+ has_company_permission('production_create', "companyId")+);++CREATE POLICY "Employees with production_update can update scrap reasons" ON "scrapReason"+ FOR UPDATE+ USING (+ has_role('employee', "companyId") AND+ has_company_permission('production_update', "companyId")+ );++CREATE POLICY "Employees with production_delete can delete scrap reasons" ON "scrapReason"+ FOR DELETE+ USING (+ has_role('employee', "companyId") AND+ has_company_permission('production_delete', "companyId")+ );\ No newline at end of file