@@ -37,18 +37,21 @@ DETAIL: Failing row contains (8, user2, {CREATE}, SCHEMA, appschema, sometable,
3737CREATE SCHEMA appschema;
3838GRANT USAGE ON SCHEMA appschema TO PUBLIC; -- missing CREATE for user1
3939GRANT CREATE ON SCHEMA appschema TO user2; -- too much
40+ CREATE SCHEMA pgabc123;
41+ GRANT USAGE ON SCHEMA pgabc123 TO user1;
4042/* table */
4143-- desired permissions
4244INSERT INTO permission_target
4345 (role_name, permissions, object_type, schema_name, object_name, column_name)
4446VALUES ('user1', ARRAY['SELECT','INSERT','UPDATE','DELETE']::perm_type[], 'TABLE', 'appschema', NULL, NULL),
45- ('user2', ARRAY['SELECT']::perm_type[], 'TABLE', 'appschema', NULL, NULL);
47+ ('user2', ARRAY['SELECT']::perm_type[], 'TABLE', 'appschema', NULL, NULL),
48+ ('user1', ARRAY['SELECT']::perm_type[], 'TABLE', 'pgabc213', 'sometable', NULL);
4649-- this should fail
4750INSERT INTO permission_target
4851 (role_name, permissions, object_type, schema_name, object_name, column_name)
4952VALUES ('user2', ARRAY['INSERT']::perm_type[], 'TABLE', 'appschema', 'apptable', 'acolumn');
5053ERROR: new row for relation "permission_target" violates check constraint "permission_target_valid"
51- DETAIL: Failing row contains (11 , user2, {INSERT}, TABLE, appschema, apptable, acolumn).
54+ DETAIL: Failing row contains (12 , user2, {INSERT}, TABLE, appschema, apptable, acolumn).
5255-- actual permissions
5356CREATE TABLE appschema.apptable (
5457 id integer PRIMARY KEY,
@@ -60,8 +63,14 @@ CREATE TABLE appschema.apptable2 (
6063 val text NOT NULL,
6164 created timestamp with time zone NOT NULL DEFAULT current_timestamp
6265); -- missing all permissions on this one
66+ CREATE TABLE pgabc123.sometable (
67+ id integer PRIMARY KEY,
68+ val text NOT NULL,
69+ created timestamp with time zone NOT NULL DEFAULT current_timestamp
70+ );
6371GRANT SELECT, INSERT, UPDATE ON appschema.apptable TO user1; -- missing DELETE
6472GRANT SELECT, INSERT ON appschema.apptable TO user2; -- extra privilege INSERT
73+ GRANT SELECT ON pgabc123.sometable TO user1;
6574/* column */
6675-- desired permissions
6776INSERT INTO permission_target
@@ -72,7 +81,7 @@ INSERT INTO permission_target
7281 (role_name, permissions, object_type, schema_name, object_name, column_name)
7382VALUES ('user2', ARRAY['DELETE']::perm_type[], 'COLUMN', 'appschema', 'apptable2', 'val');
7483ERROR: new row for relation "permission_target" violates check constraint "permission_target_valid"
75- DETAIL: Failing row contains (13 , user2, {DELETE}, COLUMN, appschema, apptable2, val).
84+ DETAIL: Failing row contains (14 , user2, {DELETE}, COLUMN, appschema, apptable2, val).
7685-- actual permissions
7786-- missing REFERENCES for user1 on apptable2.val
7887GRANT UPDATE (val) ON appschema.apptable2 TO user2; -- extra privilege UPDATE
@@ -109,7 +118,7 @@ INSERT INTO permission_target
109118 (role_name, permissions, object_type, schema_name, object_name, column_name)
110119VALUES ('users', ARRAY['UPDATE']::perm_type[], 'FUNCTION', 'appschema', 'appfun(integer)', NULL);
111120ERROR: new row for relation "permission_target" violates check constraint "permission_target_valid"
112- DETAIL: Failing row contains (21 , users, {UPDATE}, FUNCTION, appschema, appfun(integer), null).
121+ DETAIL: Failing row contains (22 , users, {UPDATE}, FUNCTION, appschema, appfun(integer), null).
113122-- actual permissions
114123CREATE FUNCTION appschema.appfun(i integer) RETURNS integer
115124 LANGUAGE sql IMMUTABLE AS
@@ -119,13 +128,14 @@ SELECT object_type, role_name, schema_name, object_name, column_name, permission
119128FROM all_permissions
120129WHERE granted
121130 AND role_name IN ('users', 'user1', 'user2')
122- AND coalesce(schema_name, 'appschema') = 'appschema'
131+ AND coalesce(schema_name, 'appschema') IN ( 'appschema', 'pgabc123')
123132ORDER BY object_type, role_name, schema_name, object_name, column_name, permission;
124133 object_type | role_name | schema_name | object_name | column_name | permission
125134-------------+-----------+-------------+-----------------+-------------+------------
126135 TABLE | user1 | appschema | apptable | | SELECT
127136 TABLE | user1 | appschema | apptable | | INSERT
128137 TABLE | user1 | appschema | apptable | | UPDATE
138+ TABLE | user1 | pgabc123 | sometable | | SELECT
129139 TABLE | user2 | appschema | apptable | | SELECT
130140 TABLE | user2 | appschema | apptable | | INSERT
131141 VIEW | user1 | appschema | appview | | SELECT
@@ -142,6 +152,7 @@ ORDER BY object_type, role_name, schema_name, object_name, column_name, permissi
142152 FUNCTION | user2 | appschema | appfun(integer) | | EXECUTE
143153 FUNCTION | users | appschema | appfun(integer) | | EXECUTE
144154 SCHEMA | user1 | appschema | | | USAGE
155+ SCHEMA | user1 | pgabc123 | | | USAGE
145156 SCHEMA | user2 | appschema | | | USAGE
146157 SCHEMA | user2 | appschema | | | CREATE
147158 SCHEMA | users | appschema | | | USAGE
@@ -152,7 +163,7 @@ ORDER BY object_type, role_name, schema_name, object_name, column_name, permissi
152163 DATABASE | user2 | | | | TEMPORARY
153164 DATABASE | users | | | | CONNECT
154165 DATABASE | users | | | | TEMPORARY
155- (29 rows)
166+ (31 rows)
156167
157168/* report differences */
158169SELECT * FROM permission_diffs()
@@ -229,7 +240,9 @@ DROP VIEW appschema.appview;
229240DROP SEQUENCE appschema.appseq;
230241DROP TABLE appschema.apptable;
231242DROP TABLE appschema.apptable2;
243+ DROP TABLE pgabc123.sometable;
232244DROP SCHEMA appschema;
245+ DROP SCHEMA pgabc123;
233246REVOKE ALL ON DATABASE contrib_regression FROM user1, user2, users;
234247DROP ROLE user1;
235248DROP ROLE user2;
0 commit comments