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

# Database branches

> Connect Neon and every Niteshift task gets its own isolated Postgres branch, with the connection string injected as an env var.

When Neon is connected to a repository, every task gets its own Postgres branch forked from a base
branch you pick. The agent can run migrations, seed data, and exercise destructive queries without
touching shared environments.

## Setup

Open **Settings → Repositories → \[repository] → Database**. Paste a project-scoped Neon API key
(starts with `napi_`), verify it, then configure:

* **Parent branch**: the Neon branch new task branches fork from. Defaults to your project's primary
  branch (typically `main`).
* **Environment variable**: name of the env var the connection string is injected as. Defaults to
  `DATABASE_URL`.
* **TTL (days)**: how long Neon keeps the branch around. Default 30.
* **Delete on task archival**: drop the branch when the task is archived (e.g. after PR merge).
  Default on.

## Branch lifecycle

When a task starts, Niteshift creates a fresh Neon branch forked from the parent branch and injects
the connection string into the environment under your chosen variable name. Your
`niteshift-setup.sh` can read the connection string and run migrations against the new branch before
the agent starts work:

```bash theme={"dark"}
pnpm db:migrate
pnpm db:seed
```

Resumed tasks reuse the same branch they had before, so state survives across pause-resume. Branches
are deleted when the task is archived (if enabled) or when the TTL expires.

<Note>
  If a long-running task outlives its branch's TTL, the next run forks a new branch from the parent.
  Raise the TTL if you need the same branch to persist longer.
</Note>
