From 54adbb1737ebe615b6bedcd38bd685cb1b8be2fc Mon Sep 17 00:00:00 2001 From: Reid Barton Date: Tue, 18 Aug 2015 21:08:22 -0700 Subject: [PATCH] Create vagrant postgres user and grant it rights to zulip{,_test} (imported from commit bb57a3f5ef8bc48553f1eff95c47894aed4ef975) --- tools/postgres-init-db | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/postgres-init-db b/tools/postgres-init-db index 341e229d58..c960c7807b 100755 --- a/tools/postgres-init-db +++ b/tools/postgres-init-db @@ -7,6 +7,8 @@ if [ "$(uname)" = "Darwin" ]; then DEFAULT_DB="postgres" fi +VAGRANTUSERNAME=$(whoami) + if [[ $# == 0 ]]; then USERNAME=zulip PASSWORD=$($(dirname $0)/../bin/get-django-setting LOCAL_DATABASE_PASSWORD) @@ -30,6 +32,19 @@ $ROOT_POSTGRES $DEFAULT_DB << EOF CREATE USER $USERNAME WITH PASSWORD '$PASSWORD'; ALTER USER $USERNAME CREATEDB; ALTER ROLE $USERNAME SET search_path TO $SEARCH_PATH; + +DO \$\$ + BEGIN + IF NOT EXISTS ( + SELECT * FROM pg_catalog.pg_user WHERE usename -- [sic] + = '$VAGRANTUSERNAME') THEN + + CREATE USER $VAGRANTUSERNAME; + END IF; + END +\$\$ ; +GRANT $USERNAME TO $VAGRANTUSERNAME; +ALTER ROLE $VAGRANTUSERNAME SET search_path TO $SEARCH_PATH; EOF umask go-rw