Create vagrant postgres user and grant it rights to zulip{,_test}

(imported from commit bb57a3f5ef8bc48553f1eff95c47894aed4ef975)
This commit is contained in:
Reid Barton 2015-08-18 21:08:22 -07:00
parent 7cffb41e13
commit 54adbb1737
1 changed files with 15 additions and 0 deletions

View File

@ -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