Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJiWr-0006Dm-O1 for pgsql-general@arkaria.postgresql.org; Fri, 27 Aug 2021 20:32:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mJiWq-0005lt-0A for pgsql-general@arkaria.postgresql.org; Fri, 27 Aug 2021 20:32:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJiWp-0005ll-2a for pgsql-general@lists.postgresql.org; Fri, 27 Aug 2021 20:32:43 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJiWi-0003r5-7q for pgsql-general@lists.postgresql.org; Fri, 27 Aug 2021 20:32:42 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 7E5315C0068; Fri, 27 Aug 2021 16:32:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 27 Aug 2021 16:32:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=G 5adiQWdjdBbsiqHm6YQoMw9kFKg1pFGquxW1pg2a4A=; b=DS5c80ZTfWwYnmLdm sUwk4+MQP/wmAs3V3WtN07GJ/lF2gH38OTqlLXpjyZOmsTVtw/sKgBPKGPhfsOoI TgwArRMXeIvuXypEaofljLBg0wgwWhxRFKB+aDnrfddNF1MD6S0uXGNbT9yJ64lA qp1D5JqEpHGBo7HvaBHBzMSzaceq2Jk2RgnOsjuKB1hKvSxrsVQ+CYyXpaifUwur 7Hyd/WjFagh4Fg5qAP2XPseVIuM3OQcp31AYxkGgb5BqSYjc04RXyAtyCBHCdYg4 tCpVREEgIyA0qnX4GqD5DI8h/ZDMmBrI3KC10GUaRqVa/QAjIoyYBq2c/SwR5QfI uqKBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=G5adiQWdjdBbsiqHm6YQoMw9kFKg1pFGquxW1pg2a 4A=; b=jWQ+x9MzHeU/XbGEC3rriBW7N/pt6MPt+yhvhVhz5R9J11C5P1nhuIcx7 FqlSacgnrC92comBwwzZcM3i3IXcYtNDhG6WcDAAIvRIfE7wRs7LQt4zKxZ+Vua9 RVq7S6IWExpplbLpFksIdvQ1kv/yLadzPwKUe8/rNYk17tKPwHsfETA/he+pFQ2q lkDbW0rfQmG2HJJjDhgB0goYDcotqoZKyDhboNCBIm7RUFJn3uZIQtSPkl7OpCAl g2LMeFYHQbaJ9qoB3OWkg8X0K+EZ/O8kMDMXx7VavdrsYgRROAAOA26cZ7HcZbRw G1DKwvjc7mFur+Y65kHG2Pd5FuZ9A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddufedgudehtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepveevfeevfeeugeffkeekhfegieeufffgteeujedv gffhueejjefhkeejleegtdegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Aug 2021 16:32:32 -0400 (EDT) Subject: Re: Idempotent DDL Updates To: Miles Elam , pgsql-general References: From: Adrian Klaver Message-ID: <4ccc99be-8e98-9733-05e6-22fa161fd02a@aklaver.com> Date: Fri, 27 Aug 2021 13:32:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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: >  * 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