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.

19.8 KB
Raw Blame
-- Generated by `pnpm --filter @carbon/database authz migration` from packages/database/src/authz. Do not edit.

-- Ships these rules to databases where `authz sync` does not run after migrations yet.

-- customerContract
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContract' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContract');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContract" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContract" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContract" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContract" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContract" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerContractAmendment
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContractAmendment' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContractAmendment');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContractAmendment" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContractAmendment" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContractAmendment" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContractAmendment" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContractAmendment" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerContractInvoice
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContractInvoice' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContractInvoice');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContractInvoice" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContractInvoice" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContractInvoice" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContractInvoice" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContractInvoice" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerContractInvoiceLine
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContractInvoiceLine' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContractInvoiceLine');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContractInvoiceLine" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContractInvoiceLine" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContractInvoiceLine" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContractInvoiceLine" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContractInvoiceLine" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerContractLedgerEntry
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContractLedgerEntry' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContractLedgerEntry');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContractLedgerEntry" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContractLedgerEntry" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContractLedgerEntry" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContractLedgerEntry" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContractLedgerEntry" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerContractLine
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContractLine' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContractLine');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContractLine" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContractLine" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContractLine" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContractLine" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContractLine" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerContractRevenue
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerContractRevenue' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerContractRevenue');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerContractRevenue" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerContractRevenue" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerContractRevenue" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerContractRevenue" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerContractRevenue" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- customerItemRentalRate
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customerItemRentalRate' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'customerItemRentalRate');
  END LOOP;
END
$authz$;
ALTER TABLE public."customerItemRentalRate" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."customerItemRentalRate" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."customerItemRentalRate" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."customerItemRentalRate" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."customerItemRentalRate" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- fixedAssetCipCost
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'fixedAssetCipCost' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'fixedAssetCipCost');
  END LOOP;
END
$authz$;
ALTER TABLE public."fixedAssetCipCost" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."fixedAssetCipCost" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."fixedAssetCipCost" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."fixedAssetCipCost" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."fixedAssetCipCost" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_delete'))::text[]));

-- fixedAssetTransfer
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'fixedAssetTransfer' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'fixedAssetTransfer');
  END LOOP;
END
$authz$;
ALTER TABLE public."fixedAssetTransfer" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."fixedAssetTransfer" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."fixedAssetTransfer" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."fixedAssetTransfer" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."fixedAssetTransfer" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_delete'))::text[]));

-- itemRentalRate
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'itemRentalRate' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'itemRentalRate');
  END LOOP;
END
$authz$;
ALTER TABLE public."itemRentalRate" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."itemRentalRate" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."itemRentalRate" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."itemRentalRate" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."itemRentalRate" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- rentalAgreement
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'rentalAgreement' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'rentalAgreement');
  END LOOP;
END
$authz$;
ALTER TABLE public."rentalAgreement" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."rentalAgreement" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."rentalAgreement" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."rentalAgreement" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."rentalAgreement" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- rentalAgreementCharge
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'rentalAgreementCharge' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'rentalAgreementCharge');
  END LOOP;
END
$authz$;
ALTER TABLE public."rentalAgreementCharge" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."rentalAgreementCharge" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."rentalAgreementCharge" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."rentalAgreementCharge" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."rentalAgreementCharge" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- rentalAgreementLine
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'rentalAgreementLine' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'rentalAgreementLine');
  END LOOP;
END
$authz$;
ALTER TABLE public."rentalAgreementLine" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."rentalAgreementLine" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."rentalAgreementLine" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."rentalAgreementLine" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."rentalAgreementLine" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- rentalBillingPeriod
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'rentalBillingPeriod' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'rentalBillingPeriod');
  END LOOP;
END
$authz$;
ALTER TABLE public."rentalBillingPeriod" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."rentalBillingPeriod" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."rentalBillingPeriod" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."rentalBillingPeriod" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."rentalBillingPeriod" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- rentalLeaseScheduleLine
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'rentalLeaseScheduleLine' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'rentalLeaseScheduleLine');
  END LOOP;
END
$authz$;
ALTER TABLE public."rentalLeaseScheduleLine" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."rentalLeaseScheduleLine" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."rentalLeaseScheduleLine" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."rentalLeaseScheduleLine" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."rentalLeaseScheduleLine" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('sales_delete'))::text[]));

-- revenueRecognitionRun
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'revenueRecognitionRun' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'revenueRecognitionRun');
  END LOOP;
END
$authz$;
ALTER TABLE public."revenueRecognitionRun" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."revenueRecognitionRun" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."revenueRecognitionRun" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."revenueRecognitionRun" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."revenueRecognitionRun" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_delete'))::text[]));

-- revenueRecognitionRunLine
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'revenueRecognitionRunLine' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'revenueRecognitionRunLine');
  END LOOP;
END
$authz$;
ALTER TABLE public."revenueRecognitionRunLine" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."revenueRecognitionRunLine" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."revenueRecognitionRunLine" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."revenueRecognitionRunLine" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."revenueRecognitionRunLine" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_delete'))::text[]));

-- revenueRecognitionSchedule
DO $authz$
DECLARE p record;
BEGIN
  FOR p IN SELECT policyname FROM pg_policies WHERE schemaname = 'public' AND tablename = 'revenueRecognitionSchedule' LOOP
    EXECUTE format('DROP POLICY %I ON public.%I', p.policyname, 'revenueRecognitionSchedule');
  END LOOP;
END
$authz$;
ALTER TABLE public."revenueRecognitionSchedule" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "public"."revenueRecognitionSchedule" FOR SELECT USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_view'))::text[]));
CREATE POLICY "INSERT" ON "public"."revenueRecognitionSchedule" FOR INSERT WITH CHECK ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_create'))::text[]));
CREATE POLICY "UPDATE" ON "public"."revenueRecognitionSchedule" FOR UPDATE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_update'))::text[]));
CREATE POLICY "DELETE" ON "public"."revenueRecognitionSchedule" FOR DELETE USING ("companyId" = ANY ((SELECT get_companies_with_employee_permission('accounting_delete'))::text[]));