X-Git-Url: https://git.cyclocoop.org/?p=lhc%2Fateliers.git;a=blobdiff_plain;f=local%2Fpostgresql-role-create;fp=local%2Fpostgresql-role-create;h=e01f0c4ba061670f5be4590c790d8e001d024350;hp=0000000000000000000000000000000000000000;hb=e2ae547ef85e29f3f9c9dfe31feffdac2653df06;hpb=d210d4efb0016a3ea2425af9f601bfe908161499 diff --git a/local/postgresql-role-create b/local/postgresql-role-create new file mode 100755 index 0000000..e01f0c4 --- /dev/null +++ b/local/postgresql-role-create @@ -0,0 +1,22 @@ +#!/bin/sh -eux +role="$1"; shift +sudo -u postgres psql "$@" -a -f - <<-EOF + \set ON_ERROR_STOP on + DO LANGUAGE plpgsql \$\$ + BEGIN + IF NOT EXISTS ( + SELECT * + FROM pg_catalog.pg_roles + WHERE rolname = '$role' + LIMIT 1 + ) THEN + CREATE ROLE $role + NOLOGIN + NOCREATEDB + NOCREATEROLE + NOINHERIT + NOSUPERUSER; + END IF; + END; + \$\$; + EOF