pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Skipping privileges for specific functions with .pgschemaignore

Open lebedev-nikita opened this issue 7 months ago • 1 comments

Hi! As we know, pgschema does not support pg extensions, so we need a way to ignore objects related to them.

Problem Example

Let's initialize database with the following code:

-- init-schema.sql

CREATE EXTENSION dblink;

CREATE TABLE users (
  id INT PRIMARY KEY
);

Then execute pgschema dump > schema.sql with empty .pgschemaignore (comments skipped):

-- schema.sql

CREATE TYPE dblink_pkey_results AS (position integer, colname text);

CREATE TABLE IF NOT EXISTS users (
    id integer,
    CONSTRAINT users_pkey PRIMARY KEY (id)
);

REVOKE EXECUTE ON FUNCTION dblink_connect_u(text) FROM PUBLIC;
REVOKE EXECUTE ON FUNCTION dblink_connect_u(text, text) FROM PUBLIC;

We need to skip type dblink_pkey_results and privilege changes on dblink_connect_u.

# .pgschemaignore

[types]
# it works
patterns = ["dblink_*"]

[functions]
# does not affect REVOKE statemenets
patterns = ["dblink_*"]

[privileges]
# does not affect REVOKE statemenets, probably because they are applied to role PUBLIC
patterns = ["PUBLIC", "public", "dblink_*", "*"]

[default_privileges]
# does not affect REVOKE statemenets, probably because they are applied to role PUBLIC
patterns = ["PUBLIC", "public", "dblink_*", "*"]

Execute pgschema dump > schema.sql again:

-- schema.sql
CREATE TABLE IF NOT EXISTS users (
    id integer,
    CONSTRAINT users_pkey PRIMARY KEY (id)
);

REVOKE EXECUTE ON FUNCTION dblink_connect_u(text) FROM PUBLIC;
REVOKE EXECUTE ON FUNCTION dblink_connect_u(text, text) FROM PUBLIC;

As we can see, REVOKE statements are not ignored by pgschema. Probably beacuse they are applied to public role, and ignoring all privilege changes applied to public is a bad idea? Then there should be a way to target dblink_connect_u in [privileges] section?

lebedev-nikita avatar Apr 07 '26 13:04 lebedev-nikita

now it works, thank you!

lebedev-nikita avatar Apr 08 '26 12:04 lebedev-nikita