pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Miles Elam <miles.elam@productops.com>
To: Julien Rouhaud <rjuju123@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Idempotent DDL Updates
Date: Mon, 30 Aug 2021 10:57:27 -0700
Message-ID: <d1297be4-d17b-0fdb-cd9e-c1ed6f6e7539@aklaver.com> (raw)
In-Reply-To: <CAALojA8wMNRdYhx=TWMP3PudWqxtRvyNE=XNNL7Mwu6dOc+8cQ@mail.gmail.com>
References: <CAALojA_KrOF4AT1LeNjcSdoMkS25QcZsftG=6c+8qB58DRgtaA@mail.gmail.com>
	<CAOBaU_ahhqLJAHk-GWu_zsx3m+vEWb6gbHt_7Stte8NdUTeCtg@mail.gmail.com>
	<CAALojA8wMNRdYhx=TWMP3PudWqxtRvyNE=XNNL7Mwu6dOc+8cQ@mail.gmail.com>

On 8/30/21 8:56 AM, Miles Elam wrote:
> 
> 
> On Fri, Aug 27, 2021 at 7:14 PM Julien Rouhaud <rjuju123@gmail.com 
> <mailto:rjuju123@gmail.com>> wrote:
> 
> 
>     Note that the IF EXISTS / IF NOT EXISTS are *not* idempotent.  If you
>     need to write idempotent schema update scripts, you need to query the
>     catalogs to check if the specific change you want to apply has already
>     been applied or not.
> 
> Poor choice of words. You're absolutely right. The goal is for the 
> script to be idempotent, not that individual statements like that are 
> idempotent.
> 
> For example, adding ADD COLUMN foo IF NOT EXISTS and DROP COLUMN… to the 
> script in addition to CREATE TABLE IF NOT EXISTS statements so that the 
> end result is always the same column definitions no matter how often the 
> script is run.
> 
> Eventually the individual ADD and DROP COLUMN statements can be removed 
> once all databases are up to date.
> 
> Not sure that querying the catalogs is strictly necessary though… Could 
> you say more?
> 
> This removes the ability to have "down" migration scripts, but I'll be 
> honest, I've never actually used a "down" script in production. If the 
> "up" script failed for some reason, the validity of the logic in the 
> "down" script is immediately suspect. It's always a new "up" script to 
> fix the problem. That's leaving aside the issue of "down" scripts not 
> getting anywhere near the same level of scrutiny and testing as "up" 
> migration scripts get.

I think you need to investigate Sqitch:

https://sqitch.org/

When working on dev database I run the deploy(up) script and then the 
revert(down) every time I do a change to make sure it does work. Not 
only that I routinely revert back to some previous state. Helped by 
Sqitch tags that allow you set a marker in your change history. I'm 
going to say that if you spend some time with the documentation you will 
find that Sqitch is the scratch that eliminates your itch:)


> 
> - Miles


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (7+ messages)  latest in thread

Message-ID: <d1297be4-d17b-0fdb-cd9e-c1ed6f6e7539@aklaver.com>
Permalink:  ../d1297be4-d17b-0fdb-cd9e-c1ed6f6e7539@aklaver.com/
Also on:    postgresql.org/message-id/d1297be4-d17b-0fdb-cd9e-c1ed6f6e7539@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, miles.elam@productops.com, rjuju123@gmail.com
  Subject: Re: Idempotent DDL Updates
  In-Reply-To: <d1297be4-d17b-0fdb-cd9e-c1ed6f6e7539@aklaver.com>
  References: <CAALojA_KrOF4AT1LeNjcSdoMkS25QcZsftG=6c+8qB58DRgtaA@mail.gmail.com> <CAOBaU_ahhqLJAHk-GWu_zsx3m+vEWb6gbHt_7Stte8NdUTeCtg@mail.gmail.com> <CAALojA8wMNRdYhx=TWMP3PudWqxtRvyNE=XNNL7Mwu6dOc+8cQ@mail.gmail.com> <d1297be4-d17b-0fdb-cd9e-c1ed6f6e7539@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox