An tool for maintaining the versioned schemas in a postgresql database.
Version DB creates a single table (
versiondb.version) in the target database
that tracks which version of each product's database schema resides in the
database. Every time it is run, it checks what version of a product's database
schema is on the database, checks the schema file, and runs all of the scripts
required to bring the database schema up to the latest version.
If a product does not exist in the database, all of the scripts will be run on the database to create a schema that is the latest version.
npm install -g versiondb
To check what schemas are currently installed on a database
To run upgrade scripts for a product
versiondb run path/to/my/awesome/product/schema.yaml
Schema files are written in YAML.
product: my-productversions:- version: "1.0"tasks:- name: Create tablesscript: 1.0/tables.sql- name: Create functionsscript: 1.0/functions.sql- name: Create usersscript: 1.0/users.sql- version: "1.1"tasks:- name: Tables and functions that support the new wizbang featurescript: 1.1/wizbang.sql- name: Tables and functions that support the new foobar featurescript: 1.1/foobar.sql
The scripts are referenced relative the schema file. Versions are considered
ordered by the order that they are in the schema file. (E.g.,
not do semver ordering or alphabetical ordering. It considers one version to be
after another version if it appears lower in the schema file.)