Skip to content

Commit 70dfd76

Browse files
authored
chore: adjust policy table reference test case (#228)
1 parent ad6b14a commit 70dfd76

File tree

12 files changed

+50
-73
lines changed

12 files changed

+50
-73
lines changed

testdata/diff/create_policy/add_policy/diff.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
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));
13
CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);
24
CREATE POLICY "my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = 'user');
35
CREATE POLICY "select" ON users FOR SELECT TO PUBLIC USING (true);

testdata/diff/create_policy/add_policy/new.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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
915
ALTER 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)
1221
CREATE 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));

testdata/diff/create_policy/add_policy/old.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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
915
ALTER TABLE users ENABLE ROW LEVEL SECURITY;

testdata/diff/create_policy/add_policy/plan.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
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",

testdata/diff/create_policy/add_policy/plan.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);
26

37
CREATE POLICY "my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = 'user');

testdata/diff/create_policy/add_policy/plan.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
Plan: 1 to modify.
1+
Plan: 2 to modify.
22

33
Summary by type:
4-
tables: 1 to modify
4+
tables: 2 to modify
55

66
Tables:
7+
~ orders
8+
+ orders_user_access (policy)
9+
+ orders (rls)
710
~ users
811
+ UserPolicy (policy)
912
+ my-policy (policy)
@@ -13,6 +16,10 @@ Tables:
1316
DDL 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+
1623
CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);
1724

1825
CREATE POLICY "my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = 'user');

testdata/diff/create_policy/same_schema_table_reference/diff.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

testdata/diff/create_policy/same_schema_table_reference/new.sql

Lines changed: 0 additions & 21 deletions
This file was deleted.

testdata/diff/create_policy/same_schema_table_reference/old.sql

Lines changed: 0 additions & 14 deletions
This file was deleted.

testdata/diff/create_policy/same_schema_table_reference/plan.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)