> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mycryptoserver.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Setup

> Provision a PostgreSQL database for My Crypto Server

My Crypto Server uses PostgreSQL. Any Postgres works, but on Vercel you don't
set up connection strings by hand at all.

## On Vercel: connect an integration (recommended)

Both **Supabase** and **Neon** are one-click integrations in the Vercel
marketplace. Either works — both have a free tier, both give you the pooled and
direct connections the app needs.

1. Go to **Vercel → your project → Integrations → Browse Marketplace**.
2. Add **Supabase** or **Neon** and create a database.
3. Connect it to your project.

That's it — the integration injects the environment variables automatically and
the app auto-detects them. There's nothing to copy or configure:

* **Supabase / Vercel Postgres** inject `POSTGRES_URL`, `POSTGRES_PRISMA_URL`,
  and `POSTGRES_URL_NON_POOLING`.
* **Neon** injects `DATABASE_URL` and `DATABASE_URL_UNPOOLED`.

The app maps whichever pair is present:

* pooled URL → `DATABASE_URL` (for route handlers)
* direct URL → `DATABASE_URL_UNPOOLED` (for migrations)

## Self-managed Postgres (advanced)

If you're hosting outside Vercel, or bringing your own database, set the two
URLs yourself. You need one **pooled** connection and one **direct**
(non-pooled) connection:

```env theme={null}
DATABASE_URL=postgres://user:pass@host/db?sslmode=require
DATABASE_URL_UNPOOLED=postgres://user:pass@direct-host/db?sslmode=require
```

## Running migrations

Migrations use [Drizzle Kit](https://orm.drizzle.team/kit-docs/overview).

```bash theme={null}
# Generate SQL migration files from the schema
pnpm db:generate

# Apply all pending migrations
pnpm db:migrate

# Seed initial merchant record (optional)
pnpm db:seed
```

For Vercel deployments, run migrations automatically as part of the build:

```json theme={null}
{
  "buildCommand": "pnpm db:migrate && pnpm build"
}
```

Or set it in `vercel.json`:

```json theme={null}
{
  "buildCommand": "pnpm db:migrate && pnpm build",
  "installCommand": "pnpm install"
}
```

## Connection URL resolution order

The app resolves database URLs in this order:

**Pooled (`DATABASE_URL`):**

1. `DATABASE_URL`
2. `POSTGRES_PRISMA_URL`
3. `POSTGRES_URL`

**Direct (`DATABASE_URL_UNPOOLED`):**

1. `DATABASE_URL_UNPOOLED`
2. `POSTGRES_URL_NON_POOLING`

You only need to set one pair — the app picks the first available value.

## Troubleshooting

**`DATABASE_URL_UNPOOLED is required` during build**
The migration runner needs a direct (non-pooled) connection. Set `DATABASE_URL_UNPOOLED` or attach Vercel Postgres storage which provides `POSTGRES_URL_NON_POOLING`.

**`Too many connections`**
Use the non-pooled URL only for migrations. Route handlers should use the pooled URL.
