Rename group

This commit is contained in:
Juan Ignacio Sánchez Lara 2015-08-10 11:21:57 +02:00
parent eafb0f4557
commit 5afdd77dcf
2 changed files with 22 additions and 9 deletions

View File

@ -1,11 +1,3 @@
CREATE OR REPLACE
FUNCTION cartodb.CDB_Group_GroupRole(group_name text)
RETURNS TEXT AS $$
BEGIN
RETURN cartoDB.CDB_Organization_Member_Group_Role_Member_Name() || '_g_' || group_name;
END
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE
FUNCTION cartodb.CDB_Group_CreateGroup(group_name text)
RETURNS TEXT AS $$
@ -29,3 +21,23 @@ BEGIN
EXECUTE 'DROP ROLE IF EXISTS "' || cartodb.CDB_Group_GroupRole(group_name) || '"';
END
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE
FUNCTION cartodb.CDB_Group_RenameGroup(old_group_name text, new_group_name text)
RETURNS VOID AS $$
BEGIN
EXECUTE 'ALTER ROLE "' || cartodb.CDB_Group_GroupRole(old_group_name) || '" RENAME TO "' || cartodb.CDB_Group_GroupRole(new_group_name) || '"';
END
$$ LANGUAGE PLPGSQL;
-----------------------
-- Private functions
-----------------------
CREATE OR REPLACE
FUNCTION cartodb.CDB_Group_GroupRole(group_name text)
RETURNS TEXT AS $$
BEGIN
RETURN cartoDB.CDB_Organization_Member_Group_Role_Member_Name() || '_g_' || group_name;
END
$$ LANGUAGE PLPGSQL;

View File

@ -155,7 +155,8 @@ function setup() {
sql cdb_testmember_2 'INSERT INTO bar VALUES (1), (2), (3), (4), (5);'
sql cdb_testmember_2 'SELECT * FROM cdb_testmember_2.bar;'
sql "SELECT cartodb.CDB_Group_CreateGroup('${GROUP_A}')"
sql "SELECT cartodb.CDB_Group_CreateGroup('${GROUP_A}_tmp')"
sql "SELECT cartodb.CDB_Group_RenameGroup('${GROUP_A}_tmp', '${GROUP_A}')"
}