Drop the role when dropping a user-defined FDW

This commit is contained in:
Rafa de la Torre
2019-07-15 17:25:48 +02:00
parent 3a10ef7e76
commit 99096d41e0
2 changed files with 14 additions and 1 deletions

View File

@@ -241,14 +241,24 @@ BEGIN
END
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- A function to drop a user-defined foreign server and all related objects
-- It does not read from CDB_Conf
--
-- Sample call:
-- SELECT cartodb.CDB_Drop_User_Foreign_Server('amazon')
--
-- Note: if there's any dependent object (i.e. foreign table) this call will fail
CREATE OR REPLACE FUNCTION @extschema@.CDB_Drop_User_Foreign_Server(fdw_name NAME)
RETURNS void AS $$
BEGIN
EXECUTE FORMAT ('DROP SCHEMA %I', fdw_name);
EXECUTE FORMAT ('DROP USER MAPPING FOR public SERVER %I', fdw_name);
EXECUTE FORMAT ('DROP SERVER %I', fdw_name);
EXECUTE FORMAT ('REVOKE USAGE ON FOREIGN DATA WRAPPER postgres_fdw FROM %I', fdw_name);
EXECUTE FORMAT ('DROP ROLE %I', fdw_name);
END
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- Set up a user foreign table

View File

@@ -626,6 +626,9 @@ EOF
sql cdb_testmember_2 "SELECT a from test_user_fdw.foo LIMIT 1;" should 42
sql cdb_testmember_1 "SELECT cartodb.CDB_Organization_Revoke_Role('test_user_fdw');"
# If there are dependent objects, we cannot drop the foreign server
sql cdb_testmember_1 "SELECT cartodb.CDB_Drop_User_Foreign_Server('test_user_fdw')" fails
# Teardown
DATABASE=fdw_target sql postgres 'REVOKE USAGE ON SCHEMA test_fdw FROM fdw_user;'