# Reylo Migrate

> Put your schema in schema.sql, and Reylo Migrate writes, checks and runs each migration, on Postgres, MySQL and SQLite.

Put your schema in a SQL file, and Reylo Migrate writes the migrations

Model your schema in `schema.sql`, write each change into a migration with `reylo migrate new`, and run it with `reylo migrate dev`:

## Basic usage

Install the `reylo` command:

**Homebrew**:

```bash
brew install reylosql/tap/reylo
```

**npm**:

```bash
npm install --global reylo
```

**curl**:

```bash
curl -fsSL https://reylo.dev/install.sh | sh
```

**PowerShell**:

```powershell
irm https://reylo.dev/install.ps1 | iex
```

**Scoop**:

```bash
scoop bucket add reylo https://github.com/reylosql/scoop-bucket
scoop install reylo
```

Start your migrations from your database:

```terminal
$ 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
```

Commit the `reylo` directory to version control (change the path with [`dir`](https://reylo.dev/docs/configuration#dir) in `.reylo.yaml`).

Edit `schema.sql`:

`schema.sql`:

```sql
create table users (
  id integer primary key,
  email text not null -- [!code --]
  email text not null, -- [!code ++]
  bio text -- [!code ++]
);
```

Write the migration:

```terminal
$ reylo migrate new add_bio
✓ Wrote reylo/migrations/20261104140347_add_bio.sql
  + column users.bio text
```

The generated migration is plain SQL. Edit it directly to add data migrations:

`20261104140347_add_bio.sql`:

```sql
alter table users add column bio text;
```

Run it on your development database:

```terminal
$ reylo migrate dev
Applying to postgres://localhost:5432/app
  ✓ 20261104140347_add_bio.sql  applied · 4 ms
✓ Wrote reylo/reylo.lock
```

Commit it with the lock, and deploy:

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

A coding agent can set it up for you:

**Set up Reylo Migrate with an agent**

```text
Set up Reylo Migrate in this project. Reylo Migrate keeps the schema in a schema.sql file and writes, checks and runs each migration on Postgres, MySQL and SQLite. Its docs are https://reylo.dev/docs/migrate, https://reylo.dev/docs/migrate/usage and https://reylo.dev/docs/migrate/cli — fetch any page as Markdown with Accept: text/markdown, or read the index at https://reylo.dev/llms.txt. Each step below links its section.

1. Install the reylo command: https://reylo.dev/docs/migrate#basic-usage
2. Point it at the development database with DATABASE_URL, or with direct_url in .reylo.yaml. If the database role can't create databases, set shadow_url too: https://reylo.dev/docs/migrate/cli#configuration
3. Start the migrations from the development database with reylo migrate init, and commit the reylo directory it writes: https://reylo.dev/docs/migrate/cli#init
4. Make a first change: edit reylo/schema.sql, generate its migration with reylo migrate new <name>, and run it with reylo migrate dev: https://reylo.dev/docs/migrate/usage#trying-a-change
   Drops and ambiguous renames are refused until you pass a flag. Ask before dropping anything: https://reylo.dev/docs/migrate/usage#disambiguation
5. Check migrations in CI with reylo migrate deploy --dry-run, run reylo migrate deploy during deployment, and check reylo migrate status afterward: https://reylo.dev/docs/migrate/usage#deploying
   On Cloudflare Durable Objects, run migrations from code instead: https://reylo.dev/docs/durable-objects#migrations
6. Install Reylo's agent skill, which gives later sessions its rules for schema changes and migrations: npx skills add reylosql/reylo --skill reylo
```
