Database

Database

NextDevTpl uses PostgreSQL with Drizzle ORM. The schema is the source of truth for auth, credits, payments, support tickets, and user data.

Main files

PathPurpose
src/db/schema.tsTable definitions
src/db/index.tsDatabase client
drizzle.config.tsDrizzle config
drizzle/Generated migration files and snapshots
src/test/utils/db.tsTest database helpers

Development workflow

For a new local database:

pnpm db:push

For a change that should be reviewed and deployed:

pnpm db:generate
pnpm db:migrate

Use Drizzle Studio to inspect local data:

pnpm db:studio

When to use push vs migrations

CommandUse it when
pnpm db:pushYou are bootstrapping or iterating on a local database
pnpm db:generateYou changed src/db/schema.ts and need a migration file
pnpm db:migrateYou want to apply committed migrations

Schema changes checklist

  1. Update src/db/schema.ts.
  2. Update any feature service/action that reads or writes the changed table.
  3. Generate or push the schema depending on environment.
  4. Add or update tests under src/test.
  5. Run pnpm typecheck and targeted tests.

Common table areas

AreaUsed by
Auth users and sessionsBetter Auth
Credits and transactionsCredits ledger and purchases
SubscriptionsPayment and plan lookup
Support ticketsUser support and admin ticket queue
Storage recordsUpload and file security tests

On this page