-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8326 from ehuelsmann/fix/1.11/migration-with-exis…
…ting-role Drop legacy role if new already exists
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
-- Define a function which will be dropped after the session ends | ||
CREATE FUNCTION pg_temp.lsmb__role(global_role text) RETURNS text | ||
LANGUAGE SQL STABLE AS | ||
$$ select coalesce((select value | ||
from defaults | ||
where setting_key = 'role_prefix'), | ||
'lsmb_' || current_database() || '__') || global_role; $$; | ||
|
||
DO $$ | ||
DECLARE | ||
t_rolename text; | ||
BEGIN | ||
select pg_temp.lsmb__role('ap_all_vouchers') into t_rolename; | ||
perform * from pg_roles where rolname = t_rolename; | ||
if found then | ||
execute 'alter role ' || quote_ident(t_rolename) || ' rename to ' || quote_ident(pg_temp.lsmb__role('ap_voucher_all')); | ||
end if; | ||
|
||
-- drop a role which doesn't have an AR equivalent and from its naming | ||
-- is at least confusing... | ||
select pg_temp.lsmb__role('ap_all_transactions') into t_rolename; | ||
execute 'drop role if exists ' || quote_ident(t_rolename); | ||
END; | ||
$$ language plpgsql; | ||
|