Migrations are SQL files using special comments to define Up and Down blocks. Files are sorted by name (use timestamps or increasing numbers).
Basic Syntax:
-- +migrate Up
CREATE TABLE people (id int);
-- +migrate Down
DROP TABLE people;
Complex Statements:
Use -- +migrate StatementBegin and -- +migrate StatementEnd to wrap complex blocks containing semicolons.
Non-transactional Migrations:
To run a migration outside of a transaction (e.g., for CREATE INDEX CONCURRENTLY in Postgres), use the notransaction option:
-- +migrate Up notransaction
CREATE UNIQUE INDEX CONCURRENTLY people_unique_id_idx ON people (id);
-- +migrate Up
CREATE TABLE people (id int);
-- +migrate StatementBegin
CREATE OR REPLACE FUNCTION do_something()
returns void AS $$
DECLARE
create_query text;
BEGIN
-- Do something here
END;
$$
language plpgsql;
-- +migrate StatementEnd
-- +migrate Down
DROP FUNCTION do_something();
DROP TABLE people;