From cf0d6192f2aebd19a16c1acbfd2ca621bb72359a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 3 Nov 2026 14:00:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BB=93=E5=86=85=E5=8A=A0=E5=B7=A5):=20?= =?UTF-8?q?=E8=A1=A5=E9=BD=90=E5=8E=9F=E6=96=99=E9=87=87=E8=B4=AD=E8=A1=A8?= =?UTF-8?q?=20RLS=EF=BC=8C=E9=81=BF=E5=85=8D=20API=20=E6=8B=92=E7=BB=9D?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20261113_processing_raw_purchase_rls.sql | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 migrations/20261113_processing_raw_purchase_rls.sql diff --git a/migrations/20261113_processing_raw_purchase_rls.sql b/migrations/20261113_processing_raw_purchase_rls.sql new file mode 100644 index 0000000..0b93cd7 --- /dev/null +++ b/migrations/20261113_processing_raw_purchase_rls.sql @@ -0,0 +1,22 @@ +-- 仓内加工原料采购表:补齐租户 RLS(新表必须与其它 tenant 表同口径) +DO $$ +DECLARE + sch text; +BEGIN + FOR sch IN + SELECT nspname FROM pg_namespace + WHERE nspname = 'tenant_template' OR nspname LIKE 'tenant\_%' + ORDER BY nspname + LOOP + IF to_regclass(format('%I.processing_raw_purchases', sch)) IS NULL THEN + CONTINUE; + END IF; + EXECUTE format('ALTER TABLE %I.processing_raw_purchases ENABLE ROW LEVEL SECURITY', sch); + EXECUTE format('ALTER TABLE %I.processing_raw_purchases FORCE ROW LEVEL SECURITY', sch); + EXECUTE format('DROP POLICY IF EXISTS tenant_isolation_processing_raw_purchases ON %I.processing_raw_purchases', sch); + EXECUTE format( + 'CREATE POLICY tenant_isolation_processing_raw_purchases ON %I.processing_raw_purchases USING ((branch_code)::text = current_setting(''app.branch_code''::text, true)) WITH CHECK ((branch_code)::text = current_setting(''app.branch_code''::text, true))', + sch + ); + END LOOP; +END $$;