For REASSIGN OWNED for foreign user mappings
authorAlvaro Herrera <[email protected]>
Fri, 11 Dec 2015 21:39:09 +0000 (18:39 -0300)
committerAlvaro Herrera <[email protected]>
Fri, 11 Dec 2015 21:39:09 +0000 (18:39 -0300)
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.

src/backend/catalog/pg_shdepend.c
src/test/regress/expected/foreign_data.out
src/test/regress/sql/foreign_data.sql

index 500f85147f7f7174f6f58ef45a0c44a59d894ce7..4e052d3cb0d97cef73ff8eb1fd2b189f005785a6 100644 (file)
@@ -40,6 +40,7 @@
 #include "catalog/pg_ts_config.h"
 #include "catalog/pg_ts_dict.h"
 #include "catalog/pg_type.h"
+#include "catalog/pg_user_mapping.h"
 #include "commands/dbcommands.h"
 #include "commands/collationcmds.h"
 #include "commands/conversioncmds.h"
@@ -1389,6 +1390,10 @@ shdepReassignOwned(List *roleids, Oid newrole)
                     */
                    break;
 
+               case UserMappingRelationId:
+                   /* ditto */
+                   break;
+
                case OperatorClassRelationId:
                    AlterOpClassOwner_oid(sdepForm->objid, newrole);
                    break;
index dbe980ec8ddb1b0710ce26dbcf323f99c8b64c5d..e06dc3de7ddc926fcae107c79ba9c92b1c44da5f 100644 (file)
@@ -1166,6 +1166,14 @@ ERROR:  foreign table "no_table" does not exist
 DROP FOREIGN TABLE IF EXISTS no_table;
 NOTICE:  foreign table "no_table" does not exist, skipping
 DROP FOREIGN TABLE foreign_schema.foreign_table_1;
+-- REASSIGN OWNED/DROP OWNED of foreign objects
+REASSIGN OWNED BY regress_test_role TO regress_test_role2;
+DROP OWNED BY regress_test_role2;
+ERROR:  cannot drop desired object(s) because other objects depend on them
+DETAIL:  user mapping for regress_test_role on server s5 depends on server s5
+HINT:  Use DROP ... CASCADE to drop the dependent objects too.
+DROP OWNED BY regress_test_role2 CASCADE;
+NOTICE:  drop cascades to user mapping for regress_test_role on server s5
 -- Cleanup
 DROP SCHEMA foreign_schema CASCADE;
 DROP ROLE regress_test_role;                                -- ERROR
@@ -1173,14 +1181,8 @@ ERROR:  role "regress_test_role" cannot be dropped because some objects depend o
 DETAIL:  privileges for server s4
 privileges for foreign-data wrapper foo
 owner of user mapping for regress_test_role on server s6
-owner of user mapping for regress_test_role on server s5
-owner of server s5
-owner of server t2
-DROP SERVER s5 CASCADE;
-NOTICE:  drop cascades to user mapping for regress_test_role on server s5
 DROP SERVER t1 CASCADE;
 NOTICE:  drop cascades to user mapping for public on server t1
-DROP SERVER t2;
 DROP USER MAPPING FOR regress_test_role SERVER s6;
 -- This test causes some order dependent cascade detail output,
 -- so switch to terse mode for it.
index 38057db7b449e0c9d4ecb81b3ec7c63b56d981e3..a2849b46fb7f8da66bf895db36298552aed2f394 100644 (file)
@@ -476,12 +476,15 @@ DROP FOREIGN TABLE no_table;                                    -- ERROR
 DROP FOREIGN TABLE IF EXISTS no_table;
 DROP FOREIGN TABLE foreign_schema.foreign_table_1;
 
+-- REASSIGN OWNED/DROP OWNED of foreign objects
+REASSIGN OWNED BY regress_test_role TO regress_test_role2;
+DROP OWNED BY regress_test_role2;
+DROP OWNED BY regress_test_role2 CASCADE;
+
 -- Cleanup
 DROP SCHEMA foreign_schema CASCADE;
 DROP ROLE regress_test_role;                                -- ERROR
-DROP SERVER s5 CASCADE;
 DROP SERVER t1 CASCADE;
-DROP SERVER t2;
 DROP USER MAPPING FOR regress_test_role SERVER s6;
 -- This test causes some order dependent cascade detail output,
 -- so switch to terse mode for it.