postgres-init-dev-db: Catch exception when recreating extant users.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-04-19 14:30:28 -07:00 committed by Tim Abbott
parent 25798c8605
commit efd22fd2ae
1 changed files with 10 additions and 2 deletions

View File

@ -50,12 +50,20 @@ if ! pg_isready -U "$POSTGRES_USER" -q; then
fi fi
"${ROOT_POSTGRES[@]}" "$DEFAULT_DB" << EOF "${ROOT_POSTGRES[@]}" "$DEFAULT_DB" << EOF
CREATE USER $USERNAME; DO \$\$BEGIN
CREATE USER $USERNAME;
EXCEPTION WHEN duplicate_object THEN
RAISE NOTICE '$USERNAME user already exists';
END\$\$;
ALTER USER $USERNAME PASSWORD '$PASSWORD'; ALTER USER $USERNAME PASSWORD '$PASSWORD';
ALTER USER $USERNAME CREATEDB; ALTER USER $USERNAME CREATEDB;
ALTER ROLE $USERNAME SET search_path TO $SEARCH_PATH; ALTER ROLE $USERNAME SET search_path TO $SEARCH_PATH;
CREATE USER $VAGRANTUSERNAME; DO \$\$BEGIN
CREATE USER $VAGRANTUSERNAME;
EXCEPTION WHEN duplicate_object THEN
RAISE NOTICE '$VAGRANTUSERNAME user already exists';
END\$\$;
GRANT $USERNAME TO $VAGRANTUSERNAME; GRANT $USERNAME TO $VAGRANTUSERNAME;
ALTER ROLE $VAGRANTUSERNAME SET search_path TO $SEARCH_PATH; ALTER ROLE $VAGRANTUSERNAME SET search_path TO $SEARCH_PATH;
EOF EOF