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 1mJjOq-0008FK-4f for pgsql-general@arkaria.postgresql.org; Fri, 27 Aug 2021 21:28:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mJjOp-0006Gn-4I for pgsql-general@arkaria.postgresql.org; Fri, 27 Aug 2021 21:28:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJjOo-0006Ge-QK for pgsql-general@lists.postgresql.org; Fri, 27 Aug 2021 21:28:30 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mJjOi-0004zQ-ER for pgsql-general@lists.postgresql.org; Fri, 27 Aug 2021 21:28:30 +0000 Received: by mail-pl1-x62a.google.com with SMTP id m17so4731529plc.6 for ; Fri, 27 Aug 2021 14:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=/sw7DfOBKWO5yT3h4ppiIJtzvYsJaE9DMSqYJLMQI70=; b=j8RA0G4ndQKsKELPqg4EJkuhvfZ3XuLDFbmsJhEJHmwxDSn8nb1GMAzMKwGOIstQi9 aHRNR71VfHRW8AGn0q7cY/CCVPDNdqSF8ZOwXtZHc9sDtzzuDokaBvbBRWUNOMLhofgi b05Xq1qCTkmV3WHaUhYjByll0ZMgvyAE1x8SGEEsoFpGztqzE+m7lzE1PtlFez8Po8v7 w96ifRWr+7KN8JUlMTT4eGUqLcwlD9zNodLndslYg2hLPDZJ+UtJClDckAtu2QLCxR+v Uz6HgBT5AmuIT2ETm6BUlqXOe+xhOQEFUAhhmlm7qNmY0UsZmzuUhAkqDpc1paJpyNM4 o16w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=/sw7DfOBKWO5yT3h4ppiIJtzvYsJaE9DMSqYJLMQI70=; b=kVMHkRfT5EsUB+ROU9w7aSdWro9vPSeehPIDxSwtm5cruhRuuiNsGdHnVBumThsgAl S9hvnjIhTQymG3yQOi252B0FO4HfIPwekqLbaIONVM8sNe0tiUT2vvgJa7kZo64ZtOGe VVSWC1syIuCsWx7wXXienhTzq9WiLi2B43Gle97u84yFE9FAg+/9zABOB0m0RRoECm3d Y4qym/xtElGwbvsoZvMowpAJojF8NBLAtlAVKlxZRVtmVn8vW4YTfT8QZrsK+obd53sg do4FLkHvnwb39r8CKAWmOAwZPmP2drjTox6xV1ZhqHzSRe00oGX4e9DbBvp/usMuXy3X sRgA== X-Gm-Message-State: AOAM530St7b3n2jOEurh47oLukVp8sPYplOcbYlUpuSw+Ou8wuFdjdHO OhNkQYH+gZIeUgKGHgqKO/Lhi9ghfZRK/A== X-Google-Smtp-Source: ABdhPJw7QccnHc0zPwpioP0li4mVEOYc6xUnwQovX68/g6EkdwpyGri+ZceCsI+U5o01ZfXcXp9eUA== X-Received: by 2002:a17:902:6bc1:b0:137:10b6:972f with SMTP id m1-20020a1709026bc100b0013710b6972fmr10365094plt.69.1630099701224; Fri, 27 Aug 2021 14:28:21 -0700 (PDT) Received: from smtpclient.apple ([204.239.251.5]) by smtp.gmail.com with ESMTPSA id j2sm6968474pfe.201.2021.08.27.14.28.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Aug 2021 14:28:20 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Rob Sargent Mime-Version: 1.0 (1.0) Subject: Re: Idempotent DDL Updates Date: Fri, 27 Aug 2021 14:28:19 -0700 Message-Id: <62014F0D-8666-40BD-9C0C-F6FBB238EED1@gmail.com> References: <4ccc99be-8e98-9733-05e6-22fa161fd02a@aklaver.com> Cc: Miles Elam , pgsql-general In-Reply-To: <4ccc99be-8e98-9733-05e6-22fa161fd02a@aklaver.com> To: Adrian Klaver X-Mailer: iPhone Mail (18G82) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Aug 27, 2021, at 1:32 PM, Adrian Klaver wro= te: >=20 > =EF=BB=BFOn 8/27/21 11:19 AM, Miles Elam wrote: >> What is the general consensus within the community on idempotent DDL scri= pts, 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-growi= ng set of migration files, but I'm just a data point of one. Obviously for o= ther 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 it= s limited cross-engine viability. But PG does have transaction DDL, preventi= ng incomplete DDL updates. However this may just be my personal bias talking= . Yet I cannot seem to discount the advantages over ever-increasing volumes o= f Flyway-style migration files & directories: For production or dev environments? The latter is made easier if the baseline moves forward regularly. For the f= ormer the sticky bit possibly has as much to do with data migration as DDL e= volution, 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 actual= ly in the DB structure >> * much more easily determining the most current version of a function/pr= ocedure (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 v= ersion of the database >> * treating database structure as code >> The drawbacks I've run across are those areas where the EXISTS/REPLACE co= nstructs aren't implemented like roles management, domains, constraints, etc= . However those cases seem to be handled with only minor increases in comple= xity with judicious use of inline plpgsql. >> In others' opinions, has DDL idempotency been viable for maintenance of P= G databases fo you in production? >=20 > For me at least you will need to show examples of what you trying to achie= ve. I'm not seeing how a migration(change) can happen without a change of so= me sort. More to the point how *EXISTS/OR REPLACE helps? >=20 >> - Miles Elam >=20 >=20 > --=20 > Adrian Klaver > adrian.klaver@aklaver.com >=20 >=20