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

# Migrations

> Running database migrations safely against your Inviolet deployment.

## Branch sequence

Always apply in this order: **dev → demo → prod**.

## Run

```bash theme={"dark"}
# from repo root
DATABASE_URL=postgres://... pnpm --filter @inviolet/db db:migrate
```

## Verify

```bash theme={"dark"}
pnpm --filter @inviolet/db db:studio
# inspect feature_trials, classifier_integrations, classifier_corrections,
# classifier_overrides, mandate_dispenses.classification_evidence column
```

## Rollback

Migrations are forward-only. To roll back, write a new migration that undoes the change. Never edit a previously-applied migration file — it breaks the migration journal.

## Common pitfalls

* Running migrations against an uncommitted prod branch — always confirm `git status` is clean.
* Forgetting to apply to demo — demo seeds rely on the latest schema.
* Adding a NOT NULL column to a hot table without a backfill — use NULL → backfill → NOT NULL pattern instead.
