# give each worker its own database

In the [shop](/docs/quickstart/), keep this resource definition:

```yaml
resources:
  db:
    kind: postgres
    seed:
      file: seed.sql
      validate: "SELECT count(*) = 2 FROM products"
```

Map the connection into the API:

```yaml
services:
  api:
    env:
      DATABASE_URL: {resource: db, output: url}
```

These are excerpts from the starter's `antil.yaml`; keep the API command, port, and readiness settings.

Start each worktree after installing its dependencies and preparing its cache:

```sh
bun install
bun run prepare:cache
antil session start --json
```

Compare the database names and engine identifiers under `data.resources.db` in the two results. The database names differ; the engine identifier matches. Credentials stay in `outputs.url.secret_ref` and are passed to the API at launch.

If you need deliberately shared writes, end the affected workers and add `sharing: seed` and `claim: {access: shared, permissions: [read, write]}` to their `db` definition before starting them. Keep identical seed inputs. Do not choose this for workers that need independent orders or schema changes.

When the work is finished, end each session. Data is retained; review [prune](/docs/reference/cli/#antil-prune) before deleting it.
