Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions testdata/diff/create_policy/add_policy/diff.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users.id FROM users));
CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);
CREATE POLICY "my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = 'user');
CREATE POLICY "select" ON users FOR SELECT TO PUBLIC USING (true);
Expand Down
16 changes: 16 additions & 0 deletions testdata/diff/create_policy/add_policy/new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ CREATE TABLE users (
role VARCHAR(50) NOT NULL
);

CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
total NUMERIC(10,2)
);

-- RLS is enabled with multiple policies demonstrating quoting scenarios
ALTER TABLE users ENABLE ROW LEVEL SECURITY;

-- RLS on orders with policy referencing users table (Issue #224)
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;

-- Policy with reserved word name (requires quoting)
CREATE POLICY "select" ON users
FOR SELECT
Expand All @@ -31,3 +40,10 @@ CREATE POLICY user_tenant_isolation ON users
FOR UPDATE
TO PUBLIC
USING (tenant_id = current_setting('app.current_tenant')::INTEGER);

-- Policy with subquery referencing another table (Issue #224)
-- Tests that same-schema table qualifiers are normalized
CREATE POLICY orders_user_access ON orders
FOR SELECT
TO PUBLIC
USING (user_id IN (SELECT id FROM users));
6 changes: 6 additions & 0 deletions testdata/diff/create_policy/add_policy/old.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ CREATE TABLE users (
role VARCHAR(50) NOT NULL
);

CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
total NUMERIC(10,2)
);

-- RLS is enabled but no policies exist yet
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
14 changes: 13 additions & 1 deletion testdata/diff/create_policy/add_policy/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
"pgschema_version": "1.5.1",
"created_at": "1970-01-01T00:00:00Z",
"source_fingerprint": {
"hash": "1c45159a6e2607b1c83b933afa76aff63b63792704098a3046ec922e8f32649f"
"hash": "9323772d9678bd1630383ff088214914f1c01c427086930540c96be45e4be387"
},
"groups": [
{
"steps": [
{
"sql": "ALTER TABLE orders ENABLE ROW LEVEL SECURITY;",
"type": "table.rls",
"operation": "create",
"path": "public.orders"
},
{
"sql": "CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users.id FROM users));",
"type": "table.policy",
"operation": "create",
"path": "public.orders.orders_user_access"
},
{
"sql": "CREATE POLICY \"UserPolicy\" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);",
"type": "table.policy",
Expand Down
4 changes: 4 additions & 0 deletions testdata/diff/create_policy/add_policy/plan.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;

CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users.id FROM users));

CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);

CREATE POLICY "my-policy" ON users FOR INSERT TO PUBLIC WITH CHECK ((role)::text = 'user');
Expand Down
11 changes: 9 additions & 2 deletions testdata/diff/create_policy/add_policy/plan.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Plan: 1 to modify.
Plan: 2 to modify.

Summary by type:
tables: 1 to modify
tables: 2 to modify

Tables:
~ orders
+ orders_user_access (policy)
+ orders (rls)
~ users
+ UserPolicy (policy)
+ my-policy (policy)
Expand All @@ -13,6 +16,10 @@ Tables:
DDL to be executed:
--------------------------------------------------

ALTER TABLE orders ENABLE ROW LEVEL SECURITY;

CREATE POLICY orders_user_access ON orders FOR SELECT TO PUBLIC USING (user_id IN ( SELECT users.id FROM users));

CREATE POLICY "UserPolicy" ON users TO PUBLIC USING (tenant_id = current_setting('app.current_tenant')::integer);

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

This file was deleted.

21 changes: 0 additions & 21 deletions testdata/diff/create_policy/same_schema_table_reference/new.sql

This file was deleted.

14 changes: 0 additions & 14 deletions testdata/diff/create_policy/same_schema_table_reference/old.sql

This file was deleted.

20 changes: 0 additions & 20 deletions testdata/diff/create_policy/same_schema_table_reference/plan.json

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions testdata/diff/create_policy/same_schema_table_reference/plan.txt

This file was deleted.