Migrations
Garvan ships a standalone migration tool called garvan-migrate. It reads SQL or JSON files from db/migrations/, applies them in version order, and records what's already been run in a tracking table.
Running migrations
./vendors/Garvan/garvan-migrate up # apply pending migrations
./vendors/Garvan/garvan-migrate down # revert the last applied migration
./vendors/Garvan/garvan-migrate status # show what's pending / applied
The tool reads its connection settings from the same .env file your app uses.
Writing a migration
Filenames follow <UTC YYYYMMDDhhmmss>_<description>.sql. Each file has two sections, marked dbmate-style:
-- migrate:up
CREATE TABLE posts (
id serial PRIMARY KEY,
title text NOT NULL,
body text,
user_id integer REFERENCES users(id),
created_at timestamp DEFAULT now()
);
-- migrate:down
DROP TABLE posts;
For per-backend variants append .<dbtype> before .sql — for example 20240501_create_posts.mysql.sql.
Rollback
Every up must have a matching down — the tool refuses to apply a migration without one. garvan-migrate down runs them in reverse order, one at a time.
For MongoDB migrations the file body is one or more top-level JSON documents. Each one is sent to db.runCommand() in order.