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 1lLCHU-0008Jz-8u for pgsql-novice@arkaria.postgresql.org; Sat, 13 Mar 2021 21:58:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lLCHT-0002gj-1d for pgsql-novice@arkaria.postgresql.org; Sat, 13 Mar 2021 21:58:43 +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 1lLCHS-0002b3-R2 for pgsql-novice@lists.postgresql.org; Sat, 13 Mar 2021 21:58:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lLCHM-0006Un-Ig for pgsql-novice@lists.postgresql.org; Sat, 13 Mar 2021 21:58:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12DLwZCW2731143; Sat, 13 Mar 2021 16:58:35 -0500 From: Tom Lane To: Simon Connah cc: "pgsql-novice@lists.postgresql.org" Subject: Re: Database migrations In-reply-to: References: Comments: In-reply-to Simon Connah message dated "Sat, 13 Mar 2021 21:40:27 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2731141.1615672715.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 13 Mar 2021 16:58:35 -0500 Message-ID: <2731142.1615672715@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Simon Connah writes: > I'm sorry if this is a rather stupid question but I'm fairly new to data= bases 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= might require changes to the database structure. What is the best way to = handle this? > I was thinking about just having a bunch of SQL files with a version num= ber and date and applying them to the database from oldest to newest (with= a table storing information for files that have already been processed). = Does 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