-
Notifications
You must be signed in to change notification settings - Fork 57
fix: dump and diff RLS enabled on partitioned tables (#471) #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
14 changes: 14 additions & 0 deletions
14
testdata/diff/create_policy/enable_rls_partitioned/new.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
26 changes: 26 additions & 0 deletions
26
testdata/diff/create_policy/enable_rls_partitioned/plan.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
16 changes: 16 additions & 0 deletions
16
testdata/diff/create_policy/enable_rls_partitioned/plan.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title and description both claim to fix "dump and diff", but only a
testdata/diff/test is added. Thedumpcommand uses the sameGetRLSTablesForSchemaquery (fixed here), so a partitioned table with RLS enabled was also silently omitted from schema dumps. Without a correspondingtestdata/dump/issue_471_*/test (withraw.sql,pgschema.sql, etc.), a future regression that re-breaks dump output for partitioned RLS tables would go undetected.