This commit is contained in:
2026-03-25 23:59:29 +08:00
parent 7964ce1033
commit 23e5df0364
46 changed files with 4168 additions and 254 deletions
+28
View File
@@ -0,0 +1,28 @@
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'sales_orders' AND column_name = 'org_id'
) THEN
ALTER TABLE sales_orders ADD COLUMN org_id bigint NOT NULL DEFAULT 0;
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'purchase_orders' AND column_name = 'org_id'
) THEN
ALTER TABLE purchase_orders ADD COLUMN org_id bigint NOT NULL DEFAULT 0;
END IF;
END $$;
ALTER TABLE sales_orders ENABLE ROW LEVEL SECURITY;
ALTER TABLE purchase_orders ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS sales_orders_org_isolation ON sales_orders;
CREATE POLICY sales_orders_org_isolation
ON sales_orders
USING (org_id::text = current_setting('app.current_org_id', true));
DROP POLICY IF EXISTS purchase_orders_org_isolation ON purchase_orders;
CREATE POLICY purchase_orders_org_isolation
ON purchase_orders
USING (org_id::text = current_setting('app.current_org_id', true));