From 22fefa4c73cf6fb9dfe6da5cc3ef46c79d48a1e3 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 13 Aug 2015 11:15:42 -0400 Subject: [PATCH] JBAS-837 sqitch deploy avoids creating existing users When deploying to a PG instance that already has KCLS users, avoid trying to create them, which would result in a sqitch deployment failure. Signed-off-by: Bill Erickson --- KCLS/sqitch/deploy/kcls-2.4-base-prod.sql | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/KCLS/sqitch/deploy/kcls-2.4-base-prod.sql b/KCLS/sqitch/deploy/kcls-2.4-base-prod.sql index a85377a9c0..61cfb81385 100644 --- a/KCLS/sqitch/deploy/kcls-2.4-base-prod.sql +++ b/KCLS/sqitch/deploy/kcls-2.4-base-prod.sql @@ -1,19 +1,27 @@ - - -- Generated 2015-04-21 10:41:11 on db03.eg.kcls.org --- These custom users may already exist... errors are OK. - BEGIN; -CREATE USER bbonner; -CREATE USER biblio; -CREATE USER kclsreporter; -CREATE USER kclsreporter2; - - \set ON_ERROR_STOP on +DO +$BODY$ +BEGIN + -- When deploying to an existing postgres instance, + -- these users may already exist. + IF NOT EXISTS ( + SELECT * + FROM pg_catalog.pg_user + WHERE usename = 'bbonner') THEN + -- if bbonner is not present, assume the other's aren't. + CREATE USER bbonner; + CREATE USER biblio; + CREATE USER kclsreporter; + CREATE USER kclsreporter2; + END IF; +END +$BODY$; + -- -- PostgreSQL database dump -- 2.11.0