pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Privileges on partitioned tables are neither dumped nor diffed

Open akuzminsky opened this issue 1 month ago • 0 comments

Version: v1.13.1 (darwin/arm64), PostgreSQL 18.6 (postgres:18), default embedded plan database

Summary

Privileges on partitioned tables are neither dumped nor diffed. A GRANT on a partitioned table in the desired state is never planned, a grant on the target that the desired state lacks is never revoked, and dump leaves it out. The same grants on an ordinary table work. The privileges query in ir/queries/queries.sql keeps only c.relkind IN ('r', 'v', 'm', 'S'), so partitioned tables ('p') are skipped.

Reproduction

-- target database
CREATE ROLE reader;
-- tables.sql
CREATE TABLE events (
    id int NOT NULL,
    at date NOT NULL
) PARTITION BY RANGE (at);

CREATE TABLE events_2026_01 PARTITION OF events FOR VALUES FROM ('2026-01-01') TO ('2026-02-01');

CREATE TABLE plain (id int NOT NULL);

with_grants.sql is tables.sql plus:

GRANT SELECT ON events TO reader;
GRANT SELECT ON plain TO reader;
  1. pgschema apply --db r3 --file tables.sql --auto-approve, then pgschema plan --db r3 --file with_grants.sql --output-sql stdout:

    GRANT SELECT ON TABLE plain TO reader;
    

    No grant for events.

  2. Grant both on the target (GRANT SELECT ON events TO reader; GRANT SELECT ON plain TO reader;):

     relname | relkind |                     relacl
    ---------+---------+------------------------------------------------
     events  | p       | {postgres=arwdDxtm/postgres,reader=r/postgres}
     plain   | r       | {postgres=arwdDxtm/postgres,reader=r/postgres}
    

    pgschema plan --db r3 --file tables.sql --output-sql stdout:

    REVOKE SELECT ON TABLE plain FROM reader;
    

    No revoke for events.

  3. pgschema dump --db r3 | grep GRANT:

    GRANT SELECT ON TABLE plain TO reader;
    

Expected

events treated like plain: GRANT SELECT ON TABLE events TO reader; in step 1, the matching REVOKE in step 2, and the grant in the dump. Probably 'p' added to the relkind list (as TABLE) in the privileges query, as #471 did for the table queries.

akuzminsky avatar Oct 09 '26 23:10 akuzminsky