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 1lLNEa-0001Sh-Jy for pgsql-novice@arkaria.postgresql.org; Sun, 14 Mar 2021 09:40:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lLNEX-0004aa-Ne for pgsql-novice@arkaria.postgresql.org; Sun, 14 Mar 2021 09:40:25 +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 1lLNEX-0004aO-FV for pgsql-novice@lists.postgresql.org; Sun, 14 Mar 2021 09:40:25 +0000 Received: from mail-40134.protonmail.ch ([185.70.40.134]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lLNET-0007Pu-C5 for pgsql-novice@lists.postgresql.org; Sun, 14 Mar 2021 09:40:24 +0000 Date: Sun, 14 Mar 2021 09:40:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1615714817; bh=/4GfXY49lNrzwWgfd3MuMve036qTGwjJhvR6th4Zkfw=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=xw0RZqsPOtqYqSzzUosSXcTm0MVsi5UqsxniLHWx2X3FGOBw90ee28+bFVHXo4hrR Q5GCnRwBlHaWUAKKS9hDEnQ3b5VxTCb/h4+bAKu68aaVhOf1739MWHM9bCHe1kNVZg VDN/BokzJIY4hKzqogjcdTu/WxiNFvsjwb66zJJk= To: Tom Lane From: Simon Connah Cc: "pgsql-novice@lists.postgresql.org" Reply-To: Simon Connah Subject: Re: Database migrations Message-ID: In-Reply-To: <2731142.1615672715@sss.pgh.pa.us> References: <2731142.1615672715@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Saturday, March 13th, 2021 at 21:58, Tom Lane wrote: > Simon Connah simon.n.connah@protonmail.com writes: > > > I'm sorry if this is a rather stupid question but I'm fairly new to dat= abases and was wondering if anyone could offer some advice? > > > I have an app I am developing using Node.js and PostgreSQL 13.2. I have= the basic tables I want to start with but I know that as development progr= esses change is going to be required. Since this is an open-source project = people are going to want to upgrade from one version to the next and that m= ight require changes to the database structure. What is the best way to han= dle this? > > > I was thinking about just having a bunch of SQL files with a version nu= mber and date and applying them to the database from oldest to newest (with= a table storing information for files that have already been processed). D= oes this sound like a reasonable solution? > > > If not could someone point me in the right direction, please? > > If I understand your requirements properly, this is already largely > > implemented in PG's "extension" infrastructure. The system can keep > > track of which version of an extension is installed, and apply the > > correct delta script on request for an upgrade (or downgrade). > > See here: > > https://www.postgresql.org/docs/current/extend-extensions.html > > The documentation mostly talks about extensions that have some > > underlying C code (in a .so library file). But it's perfectly possible > > to have an extension that consists only of SQL definitions. > > regards, tom lane Hi Tom, Thank you for the suggestion. I had no idea PostgreSQL had a feature for th= ings like that. I'll do some reading on the subject but it certainly seems interesting. Simon.