# `batches.unavailable`

The app's batch runs couldn't be read or cancelled in their database, because it can't be reached or has no table for them yet.

Area 14, [Tools](/docs/tooling.md); not declinable; the next step is usually the human's.

## Why Jadpo refuses it

`jadpo batches` reads the app's batch runs from the tables Jadpo keeps
them in, in each store a batch walks, and `cancel` writes there too.
Those tables come with the project's migrations. When the database can't
be reached, or has no such table, there is nothing to list, show or
cancel, so the command stops rather than say no run is kept.

Jadpo won't apply the migrations for you here or try another address.
The database may be production's, and whether it is the right one only
you know.

## What it looks like

A project whose `take_stock` walks every item in batches:








domains/stock/actions/take_stock.jadpo:

```jadpo
use stock/types { ItemPage }
use stock/actions { mark_seen }
use stock/queries { items }

/// Marks every item as seen, a batch at a time.
action take_stock(page: ItemPage) -> BatchRun {
    return batches.each(from: items(page), each: item -> mark_seen(item))
}
```

Here `DATABASE_URL` names a new database, to which the project's
migrations haven't been applied:

```sh
jadpo batches
```

```text
error: The database `main` has no table for batch runs yet
  reason: `jadpo_batch_runs` comes with the project's migrations, so either the database hasn't applied them, or it isn't this project's database.
  next: Run `jadpo migrate apply` if it is this project's database, then run the command again (human)
  rule: batches.unavailable
  help: https://jadpo.dev/docs/errors/batches.unavailable
```

`(human)` at the end of the `next:` line tells your coding agent to stop
and ask you which fix you want, because the choice is yours to make: it
decides which database the command reads, and whether its schema
changes.

A database whose server isn't running gives the same error, saying it
can't be reached. Here `DATABASE_URL` names a database on a port where
no server is listening:

```sh
DATABASE_URL=postgresql://localhost:5499/stock jadpo batches
```

```text
error: The database `main` can't be reached
  reason: Connecting to it failed, so no batch runs could be read.
  next: Check the database is running and its address is right, then run the command again (human)
  rule: batches.unavailable
  help: https://jadpo.dev/docs/errors/batches.unavailable
```

## How to fix it

The question is whether the address names this project's database.

**If it is this project's database, not yet migrated**, apply the
migrations, then run the command again:

```sh
jadpo migrate apply
jadpo batches
```

The tables are made, and the command lists the runs kept: none, on a
new database.

**If its server isn't running**, start the server, then run the command
again:

```sh
jadpo batches
```

The command reaches the database and lists the runs it keeps.

**If the address names another database than the one the runs are in**,
name that one with `--url`:

```sh
jadpo batches --url "$PRODUCTION_DATABASE_URL"
```

The command reads that database instead, and leaves the other alone.

## Related

- [`jadpo batches`](/docs/commands-for-services-calls-email-and-stored-data.md#jadpo-batches)
- [Batches](/docs/batches-work-over-many-items.md)
- [`jadpo migrate`](/docs/commands-for-the-database-settings-and-translations.md#jadpo-migrate)
