From e7fa74326dba86bac8172fcd8ab19ba690828e6f Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 6 Feb 2022 23:24:24 +0100 Subject: [PATCH] Add README to database upgrades directory --- etc/db/upgrades/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 etc/db/upgrades/README.md diff --git a/etc/db/upgrades/README.md b/etc/db/upgrades/README.md new file mode 100644 index 0000000..d33fd2d --- /dev/null +++ b/etc/db/upgrades/README.md @@ -0,0 +1,34 @@ +# Database schema upgrades + +When the database schema needs to be upgraded in order to provide new functionality, fix errors, etc., an upgrade script should be added to this directory. + +The script can be SQL (preferred) or anything else (Bash, Python, …) in the event of complex upgrades. + +The script itself should: + +* document what the intended changes are; +* contain instructions on how to run it; +* make the user aware of any non-obvious side effects; and +* say if it is safe to run the script multiple times on the +* same schema / database. + +## Naming + +Script files should be named `upgrade----v.sql`, where: + +* `` is a correlative two-digit index. When reaching 99, existing files will be renamed to a three digit index (001-099) and new files will use three digits. +* `` is the ID of the Git commit that last introduced a schema change. +* `` is the ID of the first Git commit expecting the updated schema. +* `` is the version of the schema. + +Note: the `` value should be updated with every change and it should be the same as reported by: + +```sql +select value->>'db_schema' as db_schema from public.info where key = 'version'; +``` + +If necessary, the wanted schema version must also be updated in `package.json`. + +## Running + +Schema upgrades are always run manually.