CLI

The commands of Reylo Migrate

Reylo Migrate is two groups of commands, one for migrations and one for a development database.

Some commands only run in development:

reylo migrate

The commands that write, check and run migrations:

Usage: reylo migrate <command> [flags]

Commands:
  init                     Start from this database
    --schema <name>        A schema to read; repeat for more (Postgres; all by default)
  new <name>               Write the next migration, from schema.sql or this database
    --drop <names>         Accept what it drops: tables, columns and partitions
    --rename <old>=<new>   Say a table or column was renamed
    --blocking             Accept a statement that blocks writes while it reads every row
  dev                      Apply pending migrations, rewinding if needed (may drop data), and write the lockfile
  deploy                   Run what the lock lists, with no shadow database
    --dry-run              Try it on a shadow database, running nothing here
      -- <command>         Then run the command, such as your build, typed against that shadow
  status                   Check that this database and the files are in step
  lock                     Write the lock from this database's history
  history push             Record the migrations this database's schema has
  history pull             Write the migrations this database ran into files

Flags:
  --url <url>              The database, in place of direct_url
  --json                   Print the result as one JSON object
  -h, --help               Print this help

init

Starts your migrations from an existing database:

$ reylo migrate init
✓ Started reylo/ from postgres://localhost:5432/app
  reylo/
  ├── schema.sql          this database's schema
  ├── migrations/
  │   └── init.sql        the same, recorded as run here
  └── reylo.lock          the order the migrations run in

On an empty database:

$ reylo migrate init
✓ Started reylo/ for an empty database
  reylo/
  ├── schema.sql          empty: declare your tables here
  ├── migrations/
  └── reylo.lock
» There are no migrations yet
  To write the first:
    reylo migrate new <name>

It reads every schema. Where its own SQL can't reproduce your schema exactly, it falls back to the database's dump. On Postgres, that needs pg_dump matching your server's version or newer.

It leaves out the history tables of other migration tools, as it leaves out its own:

ToolTable
Prisma Migrate_prisma_migrations
Drizzle Kit__drizzle_migrations, in its drizzle schema on Postgres
Knexknex_migrations, knex_migrations_lock
Kyselykysely_migration, kysely_migration_lock
node-pg-migratepgmigrations
SequelizeSequelizeMeta
MikroORMmikro_orm_migrations
Rails, Ecto, golang-migrate, dbmateschema_migrations, and Rails' ar_internal_metadata
Flywayflyway_schema_history
LiquibaseDATABASECHANGELOG, DATABASECHANGELOGLOCK
goosegoose_db_version
SQLx_sqlx_migrations
Diesel__diesel_schema_migrations
Alembicalembic_version
Djangodjango_migrations
Entity Framework Core__EFMigrationsHistory
Atlasatlas_schema_revisions, in its schema of that name on Postgres

On Supabase, it leaves out what every new Supabase database has, such as the supabase_realtime publication. It writes your changes to it, and each table's own grants:

reylo/schema.sql
alter default privileges in schema public revoke select on tables from anon;

create table profiles (
  id uuid not null,
  username text,
  constraint profiles_pkey primary key (id),
  constraint profiles_username_key unique (username)
);

alter table profiles add constraint profiles_id_fkey foreign key (id) references auth.users(id) on delete cascade;

alter publication supabase_realtime set table only profiles;

grant all on table profiles to authenticated, service_role;

grant delete, insert, maintain, references, trigger, truncate, update on table profiles to anon;

new

Writes the next migration, from your change to schema.sql.

  • It replays your migrations on a shadow database and writes the difference to schema.sql. It never reads your database's schema.
  • It first checks that your development database ran each migration as it now reads. An edited or deleted one, such as another branch's, is refused until reylo migrate dev settles it.
  • With no schema.sql, it writes what your development database has that your migrations don't. That's schemaless mode.
  • Edit the file freely, and add any data changes.
  • On Postgres, new constraints and indexes never block writes, and a table rewrite needs --blocking. A statement gives up a busy lock after half a second, and its migration runs again from the start.
  • On Postgres, a changed index or key is built beside the old one, then takes its place.
  • On Postgres, a new enum value the change also uses gets a migration of its own, before its first use. Postgres can't use a value in the transaction that adds it.
  • On MySQL, a change that copies its table while it blocks writes needs --blocking. That's most column type changes, a removed enum value and a table partitioned anew.
  • On MySQL, a trigger that changes is dropped and made again in one migration, under lock tables. No write to its table runs without it.
  • On MySQL, a partition added at the end of a range or list table is added in place. No row is copied.
  • On MySQL, a partition taken out of a table drops its rows, as on Postgres. It's refused until --drop names it, as --drop measurements.p2026.

A change it could read two ways is refused until you answer with a flag (Disambiguation):

$ reylo migrate new drop_bio --drop users.bio
$ reylo migrate new rename_title --rename posts.title=heading
$ reylo migrate new widen_amount --blocking

dev

Applies pending migrations to your development database, rewinding if needed, and writes the lockfile. A rewind may drop data:

$ reylo migrate dev
Applying to postgres://localhost:5432/app
  ↺ 20261104120000_tags.sql   rewound: it isn't in the migrations
    ! Dropped tags (3 rows)
  ✓ 20261104130000_posts.sql  applied · 3 ms
✓ Wrote reylo/reylo.lock

Each time, it takes these steps:

  1. Compareyour database

    Reads what your database ran, and keeps it as far as it agrees with your migrations, in the lock's order.

  2. Replaya shadow database

    Runs the migrations it kept on a shadow database, to read the schema they make.

  3. Rewindyour database

    Undoes what your database ran past that point, by the change from what it has to that schema.

  4. Runyour database

    Runs the migrations it hasn't run, as reylo migrate deploy will.

  5. Lockyour files

    Writes reylo.lock, listing what ran, in order.

It refuses a change made outside schema.sql and your migrations:

$ reylo migrate dev
✗ This database was changed outside reylo/schema.sql and its migrations
    alter table users add column hotfix bigint;
  To keep it, add it to reylo/schema.sql, then write its migration:
    reylo migrate new <name>
  To undo it:
    reylo run 'alter table users drop column hotfix;'
  To rebuild this database from the migrations, losing its rows:
    reylo db reset

Nothing was changed.

When nothing changed since its last run, it skips the shadow databases.

deploy

Runs the lock's pending migrations, each in one transaction with its history row. On MySQL, a schema change commits on its own, so each migration holds one change. A statement in MySQL's executable comments, such as /*!50001 … */, runs as written. It's checked both with and without each comment's text.

$ reylo migrate deploy
Applying to postgres://db.example.com/app
  ✓ 20261104140347_add_bio.sql  applied · 12 ms
✓ Applied 1 migration

On MySQL, a table's change runs in strict mode, whatever the server's sql_mode. A value its new type can't hold fails the migration, and the row is kept.

It needs no shadow database. It refuses to run:

  • On an edited schema file. A schema.sql that doesn't match the lock's checksum.
  • On a database changed by hand. Each deploy stores a fingerprint of the schema it leaves. A database that no longer matches it is refused, even for a hand-added index.

The refusal shows the change:

$ reylo migrate deploy
✗ This database was changed outside its migrations
  + column users.hotfix bigint
  If a migration makes this change, record it here, running nothing:
    reylo migrate history push
  If none does, write one and run it in development, then record it here:
    reylo migrate new <name>
    reylo migrate dev
    reylo migrate history push
  To see which migrations it matches:
    reylo migrate deploy --dry-run

Nothing was changed.

With --dry-run, it runs nothing and tries everything on shadow databases instead. Run it in CI:

$ reylo migrate deploy --dry-run
✓ This database is as its migrations left it
✓ The migrations match reylo/schema.sql
✓ Tried the pending migration on a shadow database:
    · 20261104140347_add_bio.sql

It says what each pending migration blocks and drops, written by hand or not. A constraint your rows already break fails it:

20261124235900_tidy_users.sql
alter table  drop column bio;
alter table  add constraint users_plan_check check (plan in ('free', 'pro'));

Try it on production:

$ reylo migrate deploy --dry-run --url $PROD_URL
✓ This database is as its migrations left it
✓ The migrations match reylo/schema.sql
✓ Tried the pending migration on a shadow database:
    · 20261124235900_tidy_users.sql
      ! It checks every row of users while it blocks reads and writes to it
      ! It drops users.bio, which holds a value in 1403 rows on this database
      ✗ It fails on this database: 8 rows break users_plan_check
        List them:
          select * from users where not (plan = ANY (ARRAY['free'::text, 'pro'::text]));

✗ The deploy would fail on rows this database holds
  Fix the rows, or the migration where no database has run it yet, then try again:
    reylo migrate deploy --dry-run

To type your build against the schema the deploy leaves, put it after --. It runs on the dry run's shadow database, which is dropped when it exits:

reylo migrate deploy --dry-run -- next build

A failed migration rolls back and records nothing. Fix the file, run reylo migrate dev, and deploy again. Where a database already ran the old version, write a new migration instead.

A migration can also fail on rows the database already holds. The refusal gives a query that lists them, to fix before you deploy again:

$ reylo migrate deploy
Applying to postgres://db.example.com/app
  ✓ 20261123211603_drop_team_plan.sql    applied · 44 ms
  ✗ 20261123211604_drop_team_plan_2.sql  failed

✗ The migration 20261123211604_drop_team_plan_2.sql failed on rows that break users_plan_check
  check constraint "users_plan_check" of relation "users" is violated by some row
  The migration before it, 20261123211603_drop_team_plan.sql, added users_plan_check without checking the rows already in users: rows written from now on are held to it, and those aren't.
  Nothing was recorded, so the next deploy runs it again.
  List the rows that break it:
    select * from users where not (plan = ANY (ARRAY['free'::text, 'pro'::text]));
  Fix them here, then deploy again:
    reylo migrate deploy
  If the rows are right and only development ran 20261123211604_drop_team_plan_2.sql, change users_plan_check in reylo/schema.sql and delete it, then take it off development and write the replacement:
    reylo migrate dev
    reylo migrate new <name>
    reylo migrate dev

A deploy cut off between migrations resumes once it confirms the schema hasn't changed. If that check fails or can't run (as on MySQL), run reylo migrate history push to store the fingerprint again. That command needs a shadow database.

Migrations and app builds go live at different times, so old builds fail on renamed or dropped columns. Rename in two steps. To rename users.email to contact, add contact, copy values, and deploy code that reads contact and writes both:

20261110120000_add_contact.sql
alter table  add column contact text;
update  set contact = email;

Once it runs everywhere, copy what the old build wrote meanwhile, and drop the old column:

20261112120000_drop_email.sql
update  set contact = email where contact is null or contact <> email;
alter table  drop column email;

Two things the fingerprint leaves out:

  • Comments. One added in a dashboard stops no deploy.
  • Upgrades. After you upgrade Reylo or your database's major version, the next deploy stores a new fingerprint and says so.

status

Lists what your database ran and what's pending, and checks the files. It changes nothing and needs no shadow database:

$ reylo migrate status --url $PROD_URL
Migrations on postgres://db.example.com/app
  ✓ init.sql                    applied 2026-11-04 12:00 UTC
  ✓ 20261104140347_add_bio.sql  applied 2026-11-04 15:12 UTC
  · 20261105090000_tags.sql     pending
✓ Unchanged since its last migration
✓ The migration files match reylo/reylo.lock
✓ The migrations match reylo/schema.sql
» This database hasn't run 20261105090000_tags.sql
  To run it in development:
    reylo migrate dev
  To run it in production:
    reylo migrate deploy

It exits 1 for anything out of step, such as a pending migration or a change made by hand:

$ reylo migrate status
Migrations on postgres://localhost:5432/app
  ✓ init.sql                    applied 2026-11-04 12:00 UTC
  ✓ 20261104140347_add_bio.sql  applied 2026-11-04 15:12 UTC
✓ Unchanged since its last migration
✓ The migration files match reylo/reylo.lock

✗ The schema changed since the lock was written
  The lock holds a checksum of reylo/schema.sql from when the migrations last matched it.
  If the schema changed, write its migration and run it:
    reylo migrate new <name>
    reylo migrate dev
  If only formatting or comments changed, check it again:
    reylo migrate dev

In CI, run it after a deploy. Before one, run reylo migrate deploy --dry-run.

lock

Writes the lock from your database's history. Use it to turn the lock back on or replace a lost one. It refuses where a lock exists:

$ reylo migrate lock
✓ Wrote reylo/reylo.lock: 2 migrations, in the order this database ran them
✓ The migrations match reylo/schema.sql

history push

Records your migrations as run on a database that already has their schema, running nothing:

$ reylo migrate history push --url $PROD_URL
Recording on postgres://db.example.com/app
  + 20261104160000_users_email.sql  recorded: already in place
✓ Recorded 1 migration, running nothing

A database that skipped a migration, as one another tool kept can, has the rest recorded. The skipped one moves after them in the lock, for deploy to run:

$ reylo migrate history push --url $PROD_URL
Recording on postgres://db.example.com/app
  + 20261104160000_users_email.sql  recorded: already in place
✓ Recorded 1 migration, running nothing
✓ Wrote reylo/reylo.lock: 20261103090000_revoke_public.sql now runs after 20261104160000_users_email.sql, which this database ran without it
» Development databases ran 20261103090000_revoke_public.sql first
  To record the lock's new order on one, running nothing:
    reylo migrate history push
» This database hasn't run 20261103090000_revoke_public.sql
  To run it:
    reylo migrate deploy

It moves nothing past a migration that changes data. There, it says to make the skipped migration's change and record them all.

history pull

Writes your migration files from your database's history. A deleted migration comes back, and an edited one is written over:

$ reylo migrate history pull --url $PROD_URL
Pulling from postgres://db.example.com/app
  ↓ 20261104140347_add_bio.sql  written over: it differed from what ran
Not run on this database, and left as they are: 20261105090000_tags.sql

A database changed by hand is refused.

reylo db

The commands that work on a development database directly:

Usage: reylo db <command> [flags]

Commands:
  push                     Synchronize this database with schema.sql (may be destructive)
    --drop <names>         Accept what it drops: tables, columns and partitions
    --rename <old>=<new>   Say a table or column was renamed
    --force                Accept everything it drops
    --watch                Push again on each save
  reset                    Rebuild this database from the migrations
  wipe                     Delete every row, keeping the schema
  introspect               Print this database's schema as SQL
    --schema <name>        A schema to read; repeat for more (Postgres; all by default)

Flags:
  --url <url>              The database, in place of direct_url
  --json                   Print the result as one JSON object
  -h, --help               Print this help

push

Synchronizes your development database with schema.sql, writing no migration, for trying a change:

schema.sql
create table users (
  id integer primary key,
  email text not null,
  bio text
  bio text, 
  nick text
);

Push it:

$ reylo db push
Pushing reylo/schema.sql to postgres://localhost:5432/app
  + alter table users add column nick text;
✓ This database matches reylo/schema.sql

As with reylo migrate new, a drop or a type change that loses values is refused until you name it:

schema.sql
create table users (
  id integer primary key,
  email text not null,
  bio text, 
  nick text
  bio text
);

The push is refused:

$ reylo db push
✗ This push drops the column users.nick and its data
  To drop it:
    reylo db push --drop users.nick
  To accept every destructive change:
    reylo db push --force

Nothing was changed.

Name a rename with --rename, or accept every drop with --force:

$ reylo db push --rename users.bio=about
$ reylo db push --force

With --watch, it pushes again each time you save:

$ reylo db push --watch

It refuses until reylo migrate dev has run. Until you write the migration, reylo migrate dev says so:

$ reylo migrate dev
✓ Up to date with the migrations
» The schema is ahead of the migrations
  To write the changes to a migration file:
    reylo migrate new <name>

Once you write it, reylo migrate dev records it without running it again. An empty schema.sql is refused: to start over, use reylo db reset.

reset

Rebuilds your development database from your migrations.

It checks your files first, then drops everything, empties the history and runs every migration. A platform's own objects, such as Supabase's auth.users, stay:

$ reylo db reset
Resetting postgres://localhost:5432/app
  ! Dropped users (2 rows) and emptied the history
  ✓ init.sql                    applied · 5 ms
  ✓ 20261104140347_add_bio.sql  applied · 4 ms
✓ Rebuilt from 2 migrations

wipe

Deletes every row, keeping the schema and the history.

It leaves a platform's own tables alone, such as Supabase's auth.users:

$ reylo db wipe
✓ Deleted every row of 2 tables on postgres://localhost:5432/app
» The schema and the history stay

introspect

Prints your database's schema as SQL, checked on a shadow database to make exactly what your database has:

$ reylo db introspect
create table users (
  id integer not null,
  email text not null,
  constraint users_pkey primary key (id)
);

In a terminal, a spinner shows while it reads and SQL output is coloured. Piped or redirected output is plain SQL.

Where it can't check the schema, it prints the database's own dump instead, and says why on stderr. That's where:

  • Reylo's SQL can't make all of your schema
  • your role can't create a database, and shadow_url is unset
  • --schema names only some of your schemas

On Postgres, the dump needs pg_dump of your server's version or newer. Where it checks the schema, a shadow_url whose server can't make a shadow database fails the run.

To save it over schema.sql, write a temporary file first so a failed run can't empty it:

$ reylo db introspect > schema.new.sql && mv schema.new.sql reylo/schema.sql

Configuration

Every setting is optional. These are the defaults:

.reylo.yaml
# the directory of schema.sql, the migrations, the lock and the cache
dir: reylo

# the database to migrate
direct_url: ${DATABASE_URL}

# a server for shadow databases; null uses your database's own
shadow_url: null

To migrate another database, pass --url. On Turso Cloud, that's its libsql:// URL with your auth token:

$ reylo migrate status --url $PROD_URL

Most commands use shadow databases: throwaway databases where Reylo Migrate replays your migrations to read the schema they make. A deploy needs none:

Uses a shadow databaseUses none
reylo migrate initreylo migrate deploy
reylo migrate newreylo migrate status
reylo migrate devreylo db wipe
reylo migrate deploy --dry-run
reylo migrate lock
reylo migrate history push
reylo migrate history pull
reylo db push
reylo db reset
reylo db introspect

Each database makes them its own way:

  • Postgres: on your database's server, with create database, so your role needs CREATEDB. A local superuser has it, and so do Neon's and Supabase's roles. Reylo Migrate keeps up to 32 as a cache, so a run replays only new migrations. On Azure, list each extension your migrations create in the server's azure.extensions parameter. Timescale Cloud refuses create database, so point shadow_url at the timescale/timescaledb-ha image. On Supabase, each shadow gets Supabase's schemas too, so a migration can reference auth.users, and what every new Supabase database has, such as the supabase_realtime publication.
  • MySQL: on your database's server, with create database, so your user needs the CREATE privilege on every database. PlanetScale refuses create database, so point shadow_url at a plain MySQL 8.4 server.
  • SQLite: in memory. There's nothing to grant. A Turso database's shadows run on libSQL's own engine.

Every command refuses a migration that would reach past its shadow, deploy and status included. A schema.sql that would is refused by status and by every command that loads it into a shadow. That's one with a statement that:

  • changes a role, a database, a tablespace or a server setting
  • on MySQL, names a database, as in app.users

Make roles with your server's setup, outside the migrations. Reylo doesn't inspect do blocks, so every shadow runs them on your database's server unless shadow_url names another.

Where your role can't create a database, point shadow_url at a server that can, running the same version:

.reylo.yaml
# a local Postgres 18, for a hosted Postgres 18
shadow_url: postgres://localhost:5433/postgres

Every setting, for migrations and the rest of Reylo, is in the .reylo.yaml reference.

Released under the MIT License. Copyright © 2026 Colin McDonnell.

On this page

reylosql/reylo