# CI

> How to run Reylo's type check and build in CI and on your host. A GitHub Actions workflow for Postgres, what changes for MySQL, SQLite and Cloudflare D1, and a host that builds before it migrates.

Type-check and build your queries in CI and on your host

Reylo's type check runs in CI as it does on your machine, against a database the job starts:

| | |
| --- | --- |
| Database | A throwaway one the job starts: a service container, or a file for SQLite |
| Schema | Your migrations or a schema file, applied before the type check |
| Connection | `DATABASE_URL` in the job's environment, or [`direct_url`](https://reylo.dev/configuration#direct_url) |
| Commands | The type check, then your build and your tests |
| Builds on a host | A database of its own, where the host builds before it migrates ([below](https://reylo.dev/deployment#build-before-migrate)) |

## GitHub Actions

Start Postgres as a service container, and point `DATABASE_URL` at it:

`.github/workflows/ci.yml`:

```yaml
on: [push, pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:18
        env:
          POSTGRES_PASSWORD: postgres
        ports: ["5432:5432"]
        # wait until postgres accepts connections
        options: >-
          --health-cmd pg_isready
          --health-interval 2s
          --health-retries 30
    env:
      DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
```

Then apply your schema, and run the type check, the build and your tests:

`.github/workflows/ci.yml`:

```yaml
jobs:
  check:
    # ...
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with: { node-version: 24 }
      - run: npm ci
      # your migrations, or a schema file
      - run: psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f schema.sql
      # tsc --noEmit --runExternalCode
      - run: npm run typecheck
      - run: npm run build
      - run: npm test
```

- The build reads the database too. Reylo's plugins read each query's types from it as they bundle the query, and `next build` runs the type check itself.
- A `DATABASE_URL` in the environment wins over your `.env` files. A `direct_url` in `.reylo.yaml` wins over both, so if yours names a database, point it at a variable the job sets.
- Reylo's engine is an optional dependency, installed for the runner's platform, so don't install with `--omit=optional`.
- Reylo keeps a cache of each query's analysis in `reylo/.cache/`, which git ignores. A fresh checkout has none, so the type check analyzes every query on the database.

## Schema

Apply your schema with the tool you already use, before the type check:

**Reylo Migrate**, `.github/workflows/ci.yml`:

```yaml
steps:
  # ...
  - run: npx reylo migrate deploy
  - run: npm run typecheck
```

**Prisma**, `.github/workflows/ci.yml`:

```yaml
steps:
  # ...
  - run: npx prisma migrate deploy
  - run: npm run typecheck
```

**Drizzle Kit**, `.github/workflows/ci.yml`:

```yaml
steps:
  # ...
  - run: npx drizzle-kit migrate
  - run: npm run typecheck
```

**SQL files**, `.github/workflows/ci.yml`:

```yaml
steps:
  # ...
  - run: |
      for file in migrations/*.sql; do
        psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f "$file"
      done
  - run: npm run typecheck
```

A job that skips this step fails on the first table a query reads:

```text
queries/get_user.sql(1,29): error reylo6: relation "users" does not exist (42P01)
```

## MySQL

Start MySQL in place of Postgres, and apply the schema with its client:

`.github/workflows/ci.yml`:

```yaml
jobs:
  check:
    # ...
    services:
      mysql:
        image: mysql:8.4
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
          MYSQL_DATABASE: app
        ports: ["3306:3306"]
        options: >-
          --health-cmd "mysqladmin ping -h 127.0.0.1 --silent"
          --health-interval 2s
          --health-retries 60
    env:
      DATABASE_URL: mysql://root@127.0.0.1:3306/app
    steps:
      # ...
      # tcp, not localhost's socket
      - run: mysql -h 127.0.0.1 -u root app < schema.sql
      - run: npm run typecheck
```

## SQLite

SQLite needs no service: build the database file in a step.

`.github/workflows/ci.yml`:

```yaml
jobs:
  check:
    # ...
    env:
      # the path starts at package.json
      DATABASE_URL: file:./app.db
    steps:
      # ...
      # or your migrations
      - run: sqlite3 app.db < schema.sql
      - run: npm run typecheck
```

## Cloudflare D1

Run your migrations on the local database before the type check:

`.github/workflows/ci.yml`:

```yaml
steps:
  # ...
  - run: npx reylo migrate deploy
  - run: npm run typecheck
  - run: npm run build
```

The type check reads the local file that [`direct_url`](https://reylo.dev/d1#local-database) names, so the job needs no Cloudflare account. [Cloudflare D1](https://reylo.dev/d1) and [Durable Objects](https://reylo.dev/durable-objects) cover the rest.

## A host that builds before it migrates

A host that builds before it migrates, such as Vercel, starts with no database that has your schema. Build against a database of its own:

1. Create an empty database.
2. Run your migrations into it, which also tries each one before it reaches production.
3. Run the build with [`direct_url`](https://reylo.dev/configuration#direct_url) pointed at that database.
4. Drop it.
5. Migrate your deployment's own database.

## Errors

A query that doesn't match the schema fails the job, at its line and column:

```text
queries/get_user.sql(1,18): error reylo6: column "emial" does not exist (42703)
```

The build fails on the same error. A caller that reads a column the query no longer returns fails the type check too.
