# A database on Neon (/docs/cli/neon)

`--infra neon` gives the project a [Neon](https://neon.com) PostgreSQL database instead of local services. It needs CLI 0.30.0 or newer.

```sh
pnpm dlx @clubedge/create-clubedge-app my-app --infra neon
cd my-app
pnpm db:migrate
pnpm dev
```

The CLI creates a free database through Neon's [claimable Postgres](https://neon.com/docs/reference/claimable-postgres): no account, no Docker, nothing to install. It writes two URLs into `apps/web/.env.local`, or `apps/api/.env.local` for a [frontend and its API](./frontend-and-api.mdx), since the API owns the database:

- `DATABASE_URL`: the **pooled** connection, whose host ends in `-pooler`. The app uses it.
- `DATABASE_URL_DIRECT`: the **direct** connection, the same host without `-pooler`. Migrations and the background jobs worker use it, since a transaction pooler can break them. See [pooled and direct connections](../starter/database.mdx#pooled-and-direct-connections).

<Callout type="warn">
  Neon keeps an unclaimed database for **72 hours**, with up to 100 MB. Claim it to keep it.
</Callout>

## Keep it, or start over [#keep-it-or-start-over]

```sh
pnpm clubedge neon           # where it stands and how many hours it has left
pnpm clubedge neon claim     # open Neon's page that moves it into your Neon account
pnpm clubedge neon create    # a new, empty database, for example after one expired
```

- **`neon claim`** opens a link that works for 15 minutes (`--no-open` prints it instead). Sign in to Neon (free) and accept: the database moves to your account with its data. Keep the link private, since whoever opens it gets the database.
- **After claiming**, Neon resets the database password. Open the project in the [Neon console](https://console.neon.tech), choose **Connect**, and copy the pooled connection string into `DATABASE_URL` and the direct one (pooling off) into `DATABASE_URL_DIRECT`.
- **`neon create`** replaces the two URLs. It asks first when `DATABASE_URL` points at a database that is still alive; `--yes` agrees, and `--dry-run` shows what it would do without creating anything.

The CLI keeps what it needs to claim each database in `neon.json` in its config directory (`~/.config/clubedge`, or `%APPDATA%\clubedge` on Windows; `$XDG_CONFIG_HOME/clubedge` when `XDG_CONFIG_HOME` is set). Treat that file as a secret.

## Your own Neon project [#your-own-neon-project]

To use a Neon project you already have, paste its pooled and direct connection strings into the two variables. `--no-neon` creates the project without a database:

```sh
pnpm dlx @clubedge/create-clubedge-app my-app --infra neon --no-neon
```

## Switch an existing project [#switch-an-existing-project]

```sh
pnpm clubedge add infra neon
```

It creates a database when `DATABASE_URL` still held the old local services' example value. A URL you set yourself stays, and `pnpm clubedge neon create` replaces it when you want. `--no-neon` switches the project without creating a database.

## Checks and deploys [#checks-and-deploys]

- **`doctor`** checks the two URLs: the pooled one for the app, the direct one without `-pooler`, both for the same database. It warns when a free database has less than a day left. See [Check a project](./check-a-project.mdx).
- **`deploy`** sends `DATABASE_URL_DIRECT` along with a `DATABASE_URL` from `.env.production`, and derives it from a pooled Neon URL when the file has none. It warns before deploying a database that is still unclaimed. See [Deploy with one command](./deploy/index.mdx).
- **`try --infra neon`** runs on a Railway VM against a free Neon database. See [Try on a Railway VM](./try-on-railway.mdx).
- **Pull requests** can each get their own branch of the database. See [Preview environments](../starter/deploy/preview-environments.mdx).
