From: Rob Sargent <robjsargent@gmail.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Miles Elam <miles.elam@productops.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Idempotent DDL Updates
Date: Fri, 27 Aug 2021 14:28:19 -0700
Message-ID: <62014F0D-8666-40BD-9C0C-F6FBB238EED1@gmail.com> (raw)
In-Reply-To: <4ccc99be-8e98-9733-05e6-22fa161fd02a@aklaver.com>
References: <4ccc99be-8e98-9733-05e6-22fa161fd02a@aklaver.com>
> On Aug 27, 2021, at 1:32 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
> On 8/27/21 11:19 AM, Miles Elam wrote:
>> What is the general consensus within the community on idempotent DDL scripts, ie. consistent usage of IF EXISTS/IF NOT EXISTS/OR REPLACE for SQL init files that get checked into source control?
>> My experience has been that it's much easier to manage than an ever-growing set of migration files, but I'm just a data point of one. Obviously for other engines that don't support transactional DDL, it's a non-starter, which leads me toward the notion that its lack of obvious popularity is due to its limited cross-engine viability. But PG does have transaction DDL, preventing incomplete DDL updates. However this may just be my personal bias talking. Yet I cannot seem to discount the advantages over ever-increasing volumes of Flyway-style migration files & directories:
For production or dev environments?
The latter is made easier if the baseline moves forward regularly. For the former the sticky bit possibly has as much to do with data migration as DDL evolution, especially if there are multiple instances (many customers)
>> * being able to do diffs of changes in source control
>> * limiting the size of the total SQL over time relative to what's actually in the DB structure
>> * much more easily determining the most current version of a function/procedure (this bit me hard in the past with dozens of migration files)
>> * the ability to prune old changes that no longer apply to any deployed version of the database
>> * treating database structure as code
>> The drawbacks I've run across are those areas where the EXISTS/REPLACE constructs aren't implemented like roles management, domains, constraints, etc. However those cases seem to be handled with only minor increases in complexity with judicious use of inline plpgsql.
>> In others' opinions, has DDL idempotency been viable for maintenance of PG databases fo you in production?
>
> For me at least you will need to show examples of what you trying to achieve. I'm not seeing how a migration(change) can happen without a change of some sort. More to the point how *EXISTS/OR REPLACE helps?
>
>> - Miles Elam
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
>
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: robjsargent@gmail.com, adrian.klaver@aklaver.com, miles.elam@productops.com
Subject: Re: Idempotent DDL Updates
In-Reply-To: <62014F0D-8666-40BD-9C0C-F6FBB238EED1@gmail.com>
References: <4ccc99be-8e98-9733-05e6-22fa161fd02a@aklaver.com> <62014F0D-8666-40BD-9C0C-F6FBB238EED1@gmail.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