-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating permissions objects not to error out - not a fan that you ha…
…ve to write a function in PG every time you want any logic in determine if something does NOT exist
- Loading branch information
1 parent
7542611
commit 00a8bad
Showing
2 changed files
with
25 additions
and
7 deletions.
There are no files selected for viewing
15 changes: 12 additions & 3 deletions
15
db/PostgreSQL/TestRoundhousE/permissions/GrantRobPermissions.ENV.sql.template
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
DROP USER IF EXISTS rob; | ||
|
||
CREATE USER rob WITH PASSWORD 'RHr0x0r!'; | ||
CREATE OR REPLACE FUNCTION rh_createuser() RETURNS void AS $$ | ||
DECLARE | ||
t_exists integer; | ||
BEGIN | ||
SELECT INTO t_exists COUNT(*) FROM pg_roles where lower(rolname) = lower('rob'); | ||
IF t_exists = 0 THEN | ||
EXECUTE 'CREATE USER rob WITH PASSWORD ''RHr0x0r!'';'; | ||
END IF; | ||
END; | ||
$$ LANGUAGE 'plpgsql'; | ||
SELECT rh_createuser(); | ||
DROP FUNCTION rh_createuser(); | ||
|
||
GRANT ALL PRIVILEGES ON DATABASE {{DatabaseName}} to rob; |
17 changes: 13 additions & 4 deletions
17
db/PostgreSQL/TestRoundhousE/permissions/LOCAL.GrantRobPermissions.ENV.sql
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
DROP USER IF EXISTS rob; | ||
CREATE OR REPLACE FUNCTION rh_createuser() RETURNS void AS $$ | ||
DECLARE | ||
t_exists integer; | ||
BEGIN | ||
SELECT INTO t_exists COUNT(*) FROM pg_roles where lower(rolname) = lower('rob'); | ||
IF t_exists = 0 THEN | ||
EXECUTE 'CREATE USER rob WITH PASSWORD ''RHr0x0r!'';'; | ||
END IF; | ||
END; | ||
$$ LANGUAGE 'plpgsql'; | ||
SELECT rh_createuser(); | ||
DROP FUNCTION rh_createuser(); | ||
|
||
CREATE USER rob WITH PASSWORD 'RHr0x0r!'; | ||
|
||
GRANT ALL PRIVILEGES ON DATABASE {{DatabaseName}} to rob; | ||
GRANT ALL PRIVILEGES ON DATABASE {{DatabaseName}} to rob; |