# Railway

> How to run Reylo Migrate on Railway. The pre-deploy command that migrates your database before each deploy goes live, the database URL it reads, and other images.

Reylo Migrate on Railway

Run your migrations as your service's pre-deploy command:

`.railway/railway.ts`:

```ts
const web = service("web", {
  // ...
  preDeploy: "npx reylo migrate deploy",
});
```

Apply it to your project:

```terminal
$ railway config apply
```

It runs between the build and the deploy, in a container of its own on your private network. A migration that fails stops the deploy.

## Database

Set `DATABASE_URL` from your Railway database:

`.railway/railway.ts`:

```ts
const db = postgres("postgres");

const web = service("web", {
  // ...
  env: { DATABASE_URL: db.env.DATABASE_URL },
});
```

## Builds

A build that type-checks reads your schema before the pre-deploy command migrates it. Give it [a database of its own](https://reylo.dev/deployment#build-before-migrate).

Railway's builds can't reach your private network. So use that database's public URL.

## Other images

A Next.js standalone build, or any image without your `node_modules`, has no `reylo` command. Copy it from Reylo's image, with your `reylo` directory:

**Dockerfile**:

```dockerfile
COPY --from=ghcr.io/reylosql/reylo:0.8.3 /usr/local/bin/reylo /usr/local/bin/reylo
COPY reylo/ reylo/
```

Copy `.reylo.yaml` too, if you have one. Then run it directly:

`.railway/railway.ts`:

```ts
const web = service("web", {
  // ...
  preDeploy: "reylo migrate deploy",
});
```
