Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7499776

Browse files
committed
Fix user mapping object description
We were using "user mapping for user XYZ" as description for user mappings, but that's ambiguous because users can have mappings on multiple foreign servers; therefore change it to "for user XYZ on server UVW" instead. Object identities for user mappings are also updated in the same way, in branches 9.3 and above. The incomplete description string was introduced together with the whole SQL/MED infrastructure by commit cae565e of 8.4 era, so backpatch all the way back.
1 parent 2570e28 commit 7499776

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/backend/catalog/objectaddress.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -2051,14 +2051,17 @@ getObjectDescription(const ObjectAddress *object)
20512051
HeapTuple tup;
20522052
Oid useid;
20532053
char *usename;
2054+
Form_pg_user_mapping umform;
2055+
ForeignServer *srv;
20542056

20552057
tup = SearchSysCache1(USERMAPPINGOID,
20562058
ObjectIdGetDatum(object->objectId));
20572059
if (!HeapTupleIsValid(tup))
20582060
elog(ERROR, "cache lookup failed for user mapping %u",
20592061
object->objectId);
2060-
2061-
useid = ((Form_pg_user_mapping) GETSTRUCT(tup))->umuser;
2062+
umform = (Form_pg_user_mapping) GETSTRUCT(tup);
2063+
useid = umform->umuser;
2064+
srv = GetForeignServer(umform->umserver);
20622065

20632066
ReleaseSysCache(tup);
20642067

@@ -2067,7 +2070,8 @@ getObjectDescription(const ObjectAddress *object)
20672070
else
20682071
usename = "public";
20692072

2070-
appendStringInfo(&buffer, _("user mapping for %s"), usename);
2073+
appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
2074+
srv->servername);
20712075
break;
20722076
}
20732077

@@ -3218,15 +3222,18 @@ getObjectIdentity(const ObjectAddress *object)
32183222
{
32193223
HeapTuple tup;
32203224
Oid useid;
3225+
Form_pg_user_mapping umform;
3226+
ForeignServer *srv;
32213227
const char *usename;
32223228

32233229
tup = SearchSysCache1(USERMAPPINGOID,
32243230
ObjectIdGetDatum(object->objectId));
32253231
if (!HeapTupleIsValid(tup))
32263232
elog(ERROR, "cache lookup failed for user mapping %u",
32273233
object->objectId);
3228-
3229-
useid = ((Form_pg_user_mapping) GETSTRUCT(tup))->umuser;
3234+
umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3235+
useid = umform->umuser;
3236+
srv = GetForeignServer(umform->umserver);
32303237

32313238
ReleaseSysCache(tup);
32323239

@@ -3235,7 +3242,8 @@ getObjectIdentity(const ObjectAddress *object)
32353242
else
32363243
usename = "public";
32373244

3238-
appendStringInfoString(&buffer, usename);
3245+
appendStringInfo(&buffer, "%s on server %s", usename,
3246+
srv->servername);
32393247
break;
32403248
}
32413249

src/test/regress/expected/foreign_data.out

+12-12
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ CREATE USER MAPPING FOR current_user SERVER s1;
247247
DROP FOREIGN DATA WRAPPER foo; -- ERROR
248248
ERROR: cannot drop foreign-data wrapper foo because other objects depend on it
249249
DETAIL: server s1 depends on foreign-data wrapper foo
250-
user mapping for foreign_data_user depends on server s1
250+
user mapping for foreign_data_user on server s1 depends on server s1
251251
HINT: Use DROP ... CASCADE to drop the dependent objects too.
252252
SET ROLE regress_test_role;
253253
DROP FOREIGN DATA WRAPPER foo CASCADE; -- ERROR
@@ -256,7 +256,7 @@ RESET ROLE;
256256
DROP FOREIGN DATA WRAPPER foo CASCADE;
257257
NOTICE: drop cascades to 2 other objects
258258
DETAIL: drop cascades to server s1
259-
drop cascades to user mapping for foreign_data_user
259+
drop cascades to user mapping for foreign_data_user on server s1
260260
\dew+
261261
List of foreign-data wrappers
262262
Name | Owner | Handler | Validator | Access privileges | FDW Options | Description
@@ -528,10 +528,10 @@ CREATE USER MAPPING FOR current_user SERVER s3;
528528

529529
DROP SERVER s3; -- ERROR
530530
ERROR: cannot drop server s3 because other objects depend on it
531-
DETAIL: user mapping for foreign_data_user depends on server s3
531+
DETAIL: user mapping for foreign_data_user on server s3 depends on server s3
532532
HINT: Use DROP ... CASCADE to drop the dependent objects too.
533533
DROP SERVER s3 CASCADE;
534-
NOTICE: drop cascades to user mapping for foreign_data_user
534+
NOTICE: drop cascades to user mapping for foreign_data_user on server s3
535535
\des
536536
List of foreign servers
537537
Name | Owner | Foreign-data wrapper
@@ -1142,8 +1142,8 @@ GRANT USAGE ON FOREIGN SERVER s9 TO regress_test_role;
11421142
CREATE USER MAPPING FOR current_user SERVER s9;
11431143
DROP SERVER s9 CASCADE;
11441144
NOTICE: drop cascades to 2 other objects
1145-
DETAIL: drop cascades to user mapping for public
1146-
drop cascades to user mapping for unprivileged_role
1145+
DETAIL: drop cascades to user mapping for public on server s9
1146+
drop cascades to user mapping for unprivileged_role on server s9
11471147
RESET ROLE;
11481148
CREATE SERVER s9 FOREIGN DATA WRAPPER foo;
11491149
GRANT USAGE ON FOREIGN SERVER s9 TO unprivileged_role;
@@ -1205,14 +1205,14 @@ DROP ROLE regress_test_role; -- ERROR
12051205
ERROR: role "regress_test_role" cannot be dropped because some objects depend on it
12061206
DETAIL: privileges for server s4
12071207
privileges for foreign-data wrapper foo
1208-
owner of user mapping for regress_test_role
1209-
owner of user mapping for regress_test_role
1208+
owner of user mapping for regress_test_role on server s6
1209+
owner of user mapping for regress_test_role on server s5
12101210
owner of server s5
12111211
owner of server t2
12121212
DROP SERVER s5 CASCADE;
1213-
NOTICE: drop cascades to user mapping for regress_test_role
1213+
NOTICE: drop cascades to user mapping for regress_test_role on server s5
12141214
DROP SERVER t1 CASCADE;
1215-
NOTICE: drop cascades to user mapping for public
1215+
NOTICE: drop cascades to user mapping for public on server t1
12161216
DROP SERVER t2;
12171217
DROP USER MAPPING FOR regress_test_role SERVER s6;
12181218
-- This test causes some order dependent cascade detail output,
@@ -1223,8 +1223,8 @@ NOTICE: drop cascades to 5 other objects
12231223
\set VERBOSITY default
12241224
DROP SERVER s8 CASCADE;
12251225
NOTICE: drop cascades to 2 other objects
1226-
DETAIL: drop cascades to user mapping for foreign_data_user
1227-
drop cascades to user mapping for public
1226+
DETAIL: drop cascades to user mapping for foreign_data_user on server s8
1227+
drop cascades to user mapping for public on server s8
12281228
DROP ROLE regress_test_indirect;
12291229
DROP ROLE regress_test_role;
12301230
DROP ROLE unprivileged_role; -- ERROR

0 commit comments

Comments
 (0)