Skip to content

Commit 1f8757a

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 423697e commit 1f8757a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/backend/catalog/pg_shdepend.c

+5
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"
@@ -1374,6 +1375,10 @@ shdepReassignOwned(List *roleids, Oid newrole)
13741375
*/
13751376
break;
13761377

1378+
case UserMappingRelationId:
1379+
/* ditto */
1380+
break;
1381+
13771382
case ForeignServerRelationId:
13781383
AlterForeignServerOwner_oid(sdepForm->objid, newrole);
13791384
break;

src/test/regress/expected/foreign_data.out

+8-6
Original file line numberDiff line numberDiff line change
@@ -1199,21 +1199,23 @@ ERROR: foreign table "no_table" does not exist
11991199
DROP FOREIGN TABLE IF EXISTS no_table;
12001200
NOTICE: foreign table "no_table" does not exist, skipping
12011201
DROP FOREIGN TABLE foreign_schema.foreign_table_1;
1202+
-- REASSIGN OWNED/DROP OWNED of foreign objects
1203+
REASSIGN OWNED BY regress_test_role TO regress_test_role2;
1204+
DROP OWNED BY regress_test_role2;
1205+
ERROR: cannot drop desired object(s) because other objects depend on them
1206+
DETAIL: user mapping for regress_test_role on server s5 depends on server s5
1207+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
1208+
DROP OWNED BY regress_test_role2 CASCADE;
1209+
NOTICE: drop cascades to user mapping for regress_test_role on server s5
12021210
-- Cleanup
12031211
DROP SCHEMA foreign_schema CASCADE;
12041212
DROP ROLE regress_test_role; -- ERROR
12051213
ERROR: role "regress_test_role" cannot be dropped because some objects depend on it
12061214
DETAIL: privileges for server s4
12071215
privileges for foreign-data wrapper foo
12081216
owner of user mapping for regress_test_role on server s6
1209-
owner of user mapping for regress_test_role on server s5
1210-
owner of server s5
1211-
owner of server t2
1212-
DROP SERVER s5 CASCADE;
1213-
NOTICE: drop cascades to user mapping for regress_test_role on server s5
12141217
DROP SERVER t1 CASCADE;
12151218
NOTICE: drop cascades to user mapping for public on server t1
1216-
DROP SERVER t2;
12171219
DROP USER MAPPING FOR regress_test_role SERVER s6;
12181220
-- This test causes some order dependent cascade detail output,
12191221
-- so switch to terse mode for it.

src/test/regress/sql/foreign_data.sql

+5-2
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,15 @@ DROP FOREIGN TABLE no_table; -- ERROR
519519
DROP FOREIGN TABLE IF EXISTS no_table;
520520
DROP FOREIGN TABLE foreign_schema.foreign_table_1;
521521

522+
-- REASSIGN OWNED/DROP OWNED of foreign objects
523+
REASSIGN OWNED BY regress_test_role TO regress_test_role2;
524+
DROP OWNED BY regress_test_role2;
525+
DROP OWNED BY regress_test_role2 CASCADE;
526+
522527
-- Cleanup
523528
DROP SCHEMA foreign_schema CASCADE;
524529
DROP ROLE regress_test_role; -- ERROR
525-
DROP SERVER s5 CASCADE;
526530
DROP SERVER t1 CASCADE;
527-
DROP SERVER t2;
528531
DROP USER MAPPING FOR regress_test_role SERVER s6;
529532
-- This test causes some order dependent cascade detail output,
530533
-- so switch to terse mode for it.

0 commit comments

Comments
 (0)