public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Simon Connah <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Database migrations
Date: Sat, 13 Mar 2021 16:58:35 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <DZDT1SCFF7_nJRcZylu8tod4dlTmOX1hAuAlselavvkA4HJAFbOUPC_33W7IxDtMdbzQBPYGPN6p0N58SRHjP3D-JuI8CEyRn3xL1VF4t30=@protonmail.com>
References: <DZDT1SCFF7_nJRcZylu8tod4dlTmOX1hAuAlselavvkA4HJAFbOUPC_33W7IxDtMdbzQBPYGPN6p0N58SRHjP3D-JuI8CEyRn3xL1VF4t30=@protonmail.com>

Simon Connah <[email protected]> writes:
> I'm sorry if this is a rather stupid question but I'm fairly new to databases 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 progresses 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 number 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





view thread (7+ messages)  latest in thread

reply

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Database migrations
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox