Re: [HACKERS] possibility to specify template database for pg_regress - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: [HACKERS] possibility to specify template database for pg_regress
Date
Msg-id CAB7nPqQXh_xuPSU7D3HpDDPQsbuN3axnrhkJLiC2JNQ67mVopA@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] possibility to specify template database for pg_regress  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: [HACKERS] possibility to specify template database for pg_regress  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
On Thu, Feb 9, 2017 at 5:13 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> here is a patch

Thanks.

-       for (sl = dblist; sl; sl = sl->next)
-           create_database(sl->str);
+       if (templatelist != NULL)
+       {
+           _stringlist *tl;
+
+           for (sl = dblist, tl = templatelist; sl; sl = sl->next, tl
= tl->next)
+           {
+               if (tl != NULL)
+                   create_database(sl->str, tl->str);
+               else
+               {
+                   fprintf(stderr, _("%s: the template list is
shorter than database list\n"),
+                           progname);
+                   exit(2);
+               }
+           }
+       }
+       else
+           for (sl = dblist; sl; sl = sl->next)
+               create_database(sl->str, "template0");
There is one problem here: if the length of the template list is
shorter than the database list, databases get halfly created, then
pg_regress complains, letting the instance in a half-way state. I
think that you had better do any sanity checks before creating or even
dropping existing databases.
-- 
Michael



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [HACKERS] Provide list of subscriptions and publications inpsql's completion
Next
From: Corey Huinker
Date:
Subject: Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)