Repository navigation
fix: include partitioned tables in privilege inspection (#640) - #647
Conversation
GetPrivilegesForSchema and GetColumnPrivilegesForSchema filtered pg_class by relkind 'r', 'v', 'm', 'S', so partitioned tables (relkind 'p') were never inspected. GRANT/REVOKE on a partitioned table produced no plan changes, and dump omitted its privileges. Include relkind 'p' (reported as TABLE) in both queries and regenerate queries.sql.go with sqlc v1.30.0.
[Medium impact] Expands privilege inspection to include partitioned tables. The PR appears safe to merge, with a non-blocking request for column-grant regression coverage. Findings
SummaryIncludes partitioned parents in table and column privilege inspection.
Acknowledged scope: Reviews (1) · Last reviewed commit: "fix: include partitioned tables in privi..." · Reviewed by Greptile |
| withGrants := tablesOnly + ` | ||
| GRANT SELECT ON events TO reader; | ||
| GRANT SELECT ON plain TO reader; | ||
| ` |
There was a problem hiding this comment.
The new test only grants table-wide SELECT, so it never exercises the changed GetColumnPrivilegesForSchema query. Removing 'p' from that query would leave this test passing while column grants on partitioned parents disappear again. Add a column-only grant, such as GRANT UPDATE (id) ON events TO reader, and check both its grant and revoke plans.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
🟢 Approval recommended
The focused query changes have no identified blocking defects; additional column-level coverage is optional, and tests were not rerun.
1 open finding
What changed in this PR
Fixes #640 by including partitioned parents in privilege inspection for planning and dumps.
Changes:
- Includes partitioned tables in table- and column-privilege queries.
- Updates generated query bindings.
- Adds integration coverage for table-level GRANT and REVOKE planning.
| File | Description |
|---|---|
| ir/queries/queries.sql.go | Updates generated privilege queries. |
| ir/queries/queries.sql | Includes partitioned tables and classifies them as TABLE. |
| cmd/issue_640_integration_test.go | Tests partitioned-parent grant and revoke plans. |
Files not reviewed (1)
- ir/queries/queries.sql.go: Generated file
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| AND dep.deptype = 'e' | ||
| ) | ||
| AND c.relkind IN ('r', 'v', 'm') -- tables, views, materialized views | ||
| AND c.relkind IN ('r', 'p', 'v', 'm') -- ordinary/partitioned tables, views, materialized views |
tianzhou
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the contribution

Fixes #640
Summary
GetPrivilegesForSchemaandGetColumnPrivilegesForSchemafilteredpg_class.relkindto'r', 'v', 'm', 'S'(and'r', 'v', 'm'for columns). Partitioned tables (relkind = 'p') were never inspected. As a result:GRANT ... ON <partitioned table>in the desired state produced no plan step;REVOKE;dumpomitted the partitioned table's privileges.Both queries now include
'p', which is reported as object typeTABLE.queries.sql.gowas regenerated with the pinned sqlc v1.30.0 (sqlc generateinir/queries).Note: running
sqlc generateon currentmainalso flipsGetIndexesForSchemaRow.ParentIndexandParentIndexSchemafromsql.NullStringtostring. That predates this PR (from #643's LEFT JOIN columns), and applying it would break the inspector, so those two lines are left as they are. Only this PR's query hunks change.Validation
Passed locally with Go 1.24.7 on Linux, embedded PostgreSQL 18:
New test
cmd/issue_640_integration_test.go, using a range-partitionedeventstable plus an ordinaryplaintable:GRANT SELECT ON TABLE plain TO reader;(this reproduces the bug);GRANT SELECT ON TABLE events TO reader;and the matchingREVOKEare planned.Scope
This covers privileges on the partitioned parent. Partitions are ordinary tables (
'r') and were already handled. It does not change default privileges or the role-management behavior (see #637).