From efd22fd2ae71c3ce9e3b1a45e7f1c6096f6cacf3 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 19 Apr 2019 14:30:28 -0700 Subject: [PATCH] postgres-init-dev-db: Catch exception when recreating extant users. Signed-off-by: Anders Kaseorg --- tools/setup/postgres-init-dev-db | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/setup/postgres-init-dev-db b/tools/setup/postgres-init-dev-db index 198a7e7f5c..940de6ab39 100755 --- a/tools/setup/postgres-init-dev-db +++ b/tools/setup/postgres-init-dev-db @@ -50,12 +50,20 @@ if ! pg_isready -U "$POSTGRES_USER" -q; then fi "${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 CREATEDB; 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; ALTER ROLE $VAGRANTUSERNAME SET search_path TO $SEARCH_PATH; EOF