File tree Expand file tree Collapse file tree 12 files changed +50
-73
lines changed
testdata/diff/create_policy
same_schema_table_reference Expand file tree Collapse file tree 12 files changed +50
-73
lines changed Original file line number Diff line number Diff line change 1+ ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
2+ CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users .id FROM users));
13CREATE POLICY " UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting(' app.current_tenant' )::integer );
24CREATE POLICY " my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = ' user' );
35CREATE POLICY " select" ON users FOR SELECT TO PUBLIC USING (true);
Original file line number Diff line number Diff line change @@ -5,9 +5,18 @@ CREATE TABLE users (
55 role VARCHAR (50 ) NOT NULL
66);
77
8+ CREATE TABLE orders (
9+ id SERIAL PRIMARY KEY ,
10+ user_id INTEGER REFERENCES users(id),
11+ total NUMERIC (10 ,2 )
12+ );
13+
814-- RLS is enabled with multiple policies demonstrating quoting scenarios
915ALTER TABLE users ENABLE ROW LEVEL SECURITY;
1016
17+ -- RLS on orders with policy referencing users table (Issue #224)
18+ ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
19+
1120-- Policy with reserved word name (requires quoting)
1221CREATE POLICY " select" ON users
1322 FOR SELECT
@@ -31,3 +40,10 @@ CREATE POLICY user_tenant_isolation ON users
3140 FOR UPDATE
3241 TO PUBLIC
3342 USING (tenant_id = current_setting(' app.current_tenant' )::INTEGER );
43+
44+ -- Policy with subquery referencing another table (Issue #224)
45+ -- Tests that same-schema table qualifiers are normalized
46+ CREATE POLICY orders_user_access ON orders
47+ FOR SELECT
48+ TO PUBLIC
49+ USING (user_id IN (SELECT id FROM users));
Original file line number Diff line number Diff line change @@ -5,5 +5,11 @@ CREATE TABLE users (
55 role VARCHAR (50 ) NOT NULL
66);
77
8+ CREATE TABLE orders (
9+ id SERIAL PRIMARY KEY ,
10+ user_id INTEGER REFERENCES users(id),
11+ total NUMERIC (10 ,2 )
12+ );
13+
814-- RLS is enabled but no policies exist yet
915ALTER TABLE users ENABLE ROW LEVEL SECURITY;
Original file line number Diff line number Diff line change 33 "pgschema_version" : " 1.5.1" ,
44 "created_at" : " 1970-01-01T00:00:00Z" ,
55 "source_fingerprint" : {
6- "hash" : " 1c45159a6e2607b1c83b933afa76aff63b63792704098a3046ec922e8f32649f "
6+ "hash" : " 9323772d9678bd1630383ff088214914f1c01c427086930540c96be45e4be387 "
77 },
88 "groups" : [
99 {
1010 "steps" : [
11+ {
12+ "sql" : " ALTER TABLE orders ENABLE ROW LEVEL SECURITY;" ,
13+ "type" : " table.rls" ,
14+ "operation" : " create" ,
15+ "path" : " public.orders"
16+ },
17+ {
18+ "sql" : " CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users.id FROM users));" ,
19+ "type" : " table.policy" ,
20+ "operation" : " create" ,
21+ "path" : " public.orders.orders_user_access"
22+ },
1123 {
1224 "sql" : " CREATE POLICY \" UserPolicy\" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);" ,
1325 "type" : " table.policy" ,
Original file line number Diff line number Diff line change 1+ ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
2+
3+ CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users .id FROM users));
4+
15CREATE POLICY " UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting(' app.current_tenant' )::integer );
26
37CREATE POLICY " my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = ' user' );
Original file line number Diff line number Diff line change 1- Plan: 1 to modify.
1+ Plan: 2 to modify.
22
33Summary by type:
4- tables: 1 to modify
4+ tables: 2 to modify
55
66Tables:
7+ ~ orders
8+ + orders_user_access (policy)
9+ + orders (rls)
710 ~ users
811 + UserPolicy (policy)
912 + my-policy (policy)
@@ -13,6 +16,10 @@ Tables:
1316DDL to be executed:
1417--------------------------------------------------
1518
19+ ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
20+
21+ CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users.id FROM users));
22+
1623CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);
1724
1825CREATE POLICY "my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = 'user');
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments