Skip to content

Commit

Permalink
updating permissions objects not to error out - not a fan that you ha…
Browse files Browse the repository at this point in the history
…ve to write a function in PG every time you want any logic in determine if something does NOT exist
  • Loading branch information
ferventcoder committed Nov 16, 2011
1 parent 7542611 commit 00a8bad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
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;
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;

0 comments on commit 00a8bad

Please sign in to comment.