JBAS-837 sqitch deploy avoids creating existing users
authorBill Erickson <berickxx@gmail.com>
Thu, 13 Aug 2015 15:15:42 +0000 (11:15 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
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 <berickxx@gmail.com>
KCLS/sqitch/deploy/kcls-2.4-base-prod.sql

index a85377a..61cfb81 100644 (file)
@@ -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