Skip to content

Commit 8c16155

Browse files
committed
For REASSIGN OWNED for foreign user mappings
As reported in bug #13809 by Alexander Ashurkov, the code for REASSIGN OWNED hadn't gotten word about user mappings. Deal with them in the same way default ACLs do, which is to ignore them altogether; they are handled just fine by DROP OWNED. The other foreign object cases are already handled correctly by both commands. Also add a REASSIGN OWNED statement to foreign_data test to exercise the foreign data objects. (The changes are just before the "cleanup" phase, so it shouldn't remove any existing live test.) Reported by Alexander Ashurkov, then independently by Jaime Casanova.
1 parent dccf8e9 commit 8c16155

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/backend/catalog/pg_shdepend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "catalog/pg_ts_config.h"
4444
#include "catalog/pg_ts_dict.h"
4545
#include "catalog/pg_type.h"
46+
#include "catalog/pg_user_mapping.h"
4647
#include "commands/alter.h"
4748
#include "commands/dbcommands.h"
4849
#include "commands/collationcmds.h"
@@ -1389,6 +1390,10 @@ shdepReassignOwned(List *roleids, Oid newrole)
13891390
*/
13901391
break;
13911392

1393+
case UserMappingRelationId:
1394+
/* ditto */
1395+
break;
1396+
13921397
case ForeignServerRelationId:
13931398
AlterForeignServerOwner_oid(sdepForm->objid, newrole);
13941399
break;

src/test/regress/expected/foreign_data.out

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,21 +1743,23 @@ ERROR: foreign table "no_table" does not exist
17431743
DROP FOREIGN TABLE IF EXISTS no_table;
17441744
NOTICE: foreign table "no_table" does not exist, skipping
17451745
DROP FOREIGN TABLE foreign_schema.foreign_table_1;
1746+
-- REASSIGN OWNED/DROP OWNED of foreign objects
1747+
REASSIGN OWNED BY regress_test_role TO regress_test_role2;
1748+
DROP OWNED BY regress_test_role2;
1749+
ERROR: cannot drop desired object(s) because other objects depend on them
1750+
DETAIL: user mapping for regress_test_role on server s5 depends on server s5
1751+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
1752+
DROP OWNED BY regress_test_role2 CASCADE;
1753+
NOTICE: drop cascades to user mapping for regress_test_role on server s5
17461754
-- Cleanup
17471755
DROP SCHEMA foreign_schema CASCADE;
17481756
DROP ROLE regress_test_role; -- ERROR
17491757
ERROR: role "regress_test_role" cannot be dropped because some objects depend on it
17501758
DETAIL: privileges for server s4
17511759
privileges for foreign-data wrapper foo
17521760
owner of user mapping for regress_test_role on server s6
1753-
owner of user mapping for regress_test_role on server s5
1754-
owner of server s5
1755-
owner of server t2
1756-
DROP SERVER s5 CASCADE;
1757-
NOTICE: drop cascades to user mapping for regress_test_role on server s5
17581761
DROP SERVER t1 CASCADE;
17591762
NOTICE: drop cascades to user mapping for public on server t1
1760-
DROP SERVER t2;
17611763
DROP USER MAPPING FOR regress_test_role SERVER s6;
17621764
-- This test causes some order dependent cascade detail output,
17631765
-- so switch to terse mode for it.

src/test/regress/sql/foreign_data.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,15 @@ DROP FOREIGN TABLE no_table; -- ERROR
679679
DROP FOREIGN TABLE IF EXISTS no_table;
680680
DROP FOREIGN TABLE foreign_schema.foreign_table_1;
681681

682+
-- REASSIGN OWNED/DROP OWNED of foreign objects
683+
REASSIGN OWNED BY regress_test_role TO regress_test_role2;
684+
DROP OWNED BY regress_test_role2;
685+
DROP OWNED BY regress_test_role2 CASCADE;
686+
682687
-- Cleanup
683688
DROP SCHEMA foreign_schema CASCADE;
684689
DROP ROLE regress_test_role; -- ERROR
685-
DROP SERVER s5 CASCADE;
686690
DROP SERVER t1 CASCADE;
687-
DROP SERVER t2;
688691
DROP USER MAPPING FOR regress_test_role SERVER s6;
689692
-- This test causes some order dependent cascade detail output,
690693
-- so switch to terse mode for it.

0 commit comments

Comments
 (0)