diff --git a/ir/queries/queries.sql b/ir/queries/queries.sql index 7d213674..b69cdafd 100644 --- a/ir/queries/queries.sql +++ b/ir/queries/queries.sql @@ -775,7 +775,7 @@ WHERE n.nspname NOT IN ('information_schema', 'pg_catalog', 'pg_toast') AND n.nspname NOT LIKE 'pg_temp_%' AND n.nspname NOT LIKE 'pg_toast_temp_%' - AND c.relkind = 'r' + AND c.relkind IN ('r', 'p') -- ordinary and partitioned tables (issue #471) AND c.relrowsecurity = true ORDER BY n.nspname, c.relname; @@ -837,7 +837,7 @@ FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = $1 - AND c.relkind = 'r' + AND c.relkind IN ('r', 'p') -- ordinary and partitioned tables (issue #471) AND c.relrowsecurity = true ORDER BY n.nspname, c.relname; diff --git a/ir/queries/queries.sql.go b/ir/queries/queries.sql.go index a29fd9a9..9424eaf7 100644 --- a/ir/queries/queries.sql.go +++ b/ir/queries/queries.sql.go @@ -2590,7 +2590,7 @@ WHERE n.nspname NOT IN ('information_schema', 'pg_catalog', 'pg_toast') AND n.nspname NOT LIKE 'pg_temp_%' AND n.nspname NOT LIKE 'pg_toast_temp_%' - AND c.relkind = 'r' + AND c.relkind IN ('r', 'p') -- ordinary and partitioned tables (issue #471) AND c.relrowsecurity = true ORDER BY n.nspname, c.relname ` @@ -2641,7 +2641,7 @@ FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE n.nspname = $1 - AND c.relkind = 'r' + AND c.relkind IN ('r', 'p') -- ordinary and partitioned tables (issue #471) AND c.relrowsecurity = true ORDER BY n.nspname, c.relname ` diff --git a/testdata/diff/create_policy/enable_rls_partitioned/diff.sql b/testdata/diff/create_policy/enable_rls_partitioned/diff.sql new file mode 100644 index 00000000..d5922bf5 --- /dev/null +++ b/testdata/diff/create_policy/enable_rls_partitioned/diff.sql @@ -0,0 +1,3 @@ +ALTER TABLE events ENABLE ROW LEVEL SECURITY; + +CREATE POLICY events_org_isolation ON events TO PUBLIC USING (org_id = (NULLIF(current_setting('app.current_org_id', true), ''::text))::uuid); diff --git a/testdata/diff/create_policy/enable_rls_partitioned/new.sql b/testdata/diff/create_policy/enable_rls_partitioned/new.sql new file mode 100644 index 00000000..eeae22b5 --- /dev/null +++ b/testdata/diff/create_policy/enable_rls_partitioned/new.sql @@ -0,0 +1,14 @@ +CREATE TABLE events ( + id uuid NOT NULL, + org_id uuid NOT NULL, + created_at timestamptz NOT NULL, + PRIMARY KEY (created_at, id) +) PARTITION BY RANGE (created_at); + +-- RLS is now enabled with a policy on a partitioned table (issue #471) +ALTER TABLE events ENABLE ROW LEVEL SECURITY; + +CREATE POLICY events_org_isolation ON events + FOR ALL + TO PUBLIC + USING (org_id = NULLIF(current_setting('app.current_org_id', true), '')::uuid); diff --git a/testdata/diff/create_policy/enable_rls_partitioned/old.sql b/testdata/diff/create_policy/enable_rls_partitioned/old.sql new file mode 100644 index 00000000..2cb9f406 --- /dev/null +++ b/testdata/diff/create_policy/enable_rls_partitioned/old.sql @@ -0,0 +1,8 @@ +CREATE TABLE events ( + id uuid NOT NULL, + org_id uuid NOT NULL, + created_at timestamptz NOT NULL, + PRIMARY KEY (created_at, id) +) PARTITION BY RANGE (created_at); + +-- RLS is not enabled diff --git a/testdata/diff/create_policy/enable_rls_partitioned/plan.json b/testdata/diff/create_policy/enable_rls_partitioned/plan.json new file mode 100644 index 00000000..958535e0 --- /dev/null +++ b/testdata/diff/create_policy/enable_rls_partitioned/plan.json @@ -0,0 +1,26 @@ +{ + "version": "1.0.0", + "pgschema_version": "1.11.1", + "created_at": "1970-01-01T00:00:00Z", + "source_fingerprint": { + "hash": "2432fe99d3b1ab277b6fff72041a7c4400ada76e7e1ef6dbb04874d87dbc6129" + }, + "groups": [ + { + "steps": [ + { + "sql": "ALTER TABLE events ENABLE ROW LEVEL SECURITY;", + "type": "table.rls", + "operation": "create", + "path": "public.events" + }, + { + "sql": "CREATE POLICY events_org_isolation ON events TO PUBLIC USING (org_id = (NULLIF(current_setting('app.current_org_id', true), ''::text))::uuid);", + "type": "table.policy", + "operation": "create", + "path": "public.events.events_org_isolation" + } + ] + } + ] +} diff --git a/testdata/diff/create_policy/enable_rls_partitioned/plan.sql b/testdata/diff/create_policy/enable_rls_partitioned/plan.sql new file mode 100644 index 00000000..d5922bf5 --- /dev/null +++ b/testdata/diff/create_policy/enable_rls_partitioned/plan.sql @@ -0,0 +1,3 @@ +ALTER TABLE events ENABLE ROW LEVEL SECURITY; + +CREATE POLICY events_org_isolation ON events TO PUBLIC USING (org_id = (NULLIF(current_setting('app.current_org_id', true), ''::text))::uuid); diff --git a/testdata/diff/create_policy/enable_rls_partitioned/plan.txt b/testdata/diff/create_policy/enable_rls_partitioned/plan.txt new file mode 100644 index 00000000..5347c477 --- /dev/null +++ b/testdata/diff/create_policy/enable_rls_partitioned/plan.txt @@ -0,0 +1,16 @@ +Plan: 1 to modify. + +Summary by type: + tables: 1 to modify + +Tables: + ~ events + + events_org_isolation (policy) + + events (rls) + +DDL to be executed: +-------------------------------------------------- + +ALTER TABLE events ENABLE ROW LEVEL SECURITY; + +CREATE POLICY events_org_isolation ON events TO PUBLIC USING (org_id = (NULLIF(current_setting('app.current_org_id', true), ''::text))::uuid);