What is it?
Morph is a simple tool to migrate databases on PostgreSQL. It supports rollbacking from other versions without requiring the migration files from the previous version. Hence, to migrate to a new version, you only need the migration files from this particular version.
Each migration file should be prefixed with a numerical identifier. These
identifiers determine the order in which the migrations are going to be ran.
Thus, a good way to avoid conflict with other commiters is to prefix it with a
timestamp formatted as
Each migration has two SQL files: one ending with
.up.sql and the other by
.down.sql, respectively the request to migrate and the one to rollback.
Failing to have a
.down.sql file will result in an error when attempting to
rollback but will not prevent the initial migration.
For example, you could have the following files:
CREATE TABLE users ( id serial PRIMARY KEY, username varchar NOT NULL UNIQUE CHECK (username <> ''), password varchar NOT NULL CHECK (password <> '') );
DROP TABLE users;
ALTER TABLE users ADD COLUMN email varchar;
ALTER TABLE users DROP COLUMN email;
Morph reads the database connection information from a config file. This is intended to be the same file you use for your application. It supports YAML and JSON at the moment. An object (potentially nested, see options) needs to be available with the following structure:
username: _postgresql password: "" hostname: 127.0.0.1 port: 5432 name: my_database
morph --help for details about command-line options.