init
This commit is contained in:
@@ -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));
|
||||
Reference in New Issue
Block a user