Database
Database
NextDevTpl uses PostgreSQL with Drizzle ORM. The generator composes schema groups from selected modules, so tables for unselected modules do not enter the generated project.
Main files
| Path | Purpose |
|---|---|
src/db/schema/ | Tables split into auth, credits, subscription, support, and mail groups |
src/db/schema/index.ts | Schema exports selected for this generated project |
src/db/index.ts | Database client |
drizzle.config.ts | Drizzle config |
drizzle/ | Generated migration files and snapshots |
src/test/utils/db.ts | Test 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
| Command | Use it when |
|---|---|
pnpm db:push | You are bootstrapping or iterating on a local database |
pnpm db:generate | You changed src/db/schema/ and need a migration file |
pnpm db:migrate | You want to apply committed migrations |
Schema changes checklist
- Update
src/db/schema/<group>.ts; give a new module its own group. - Update any feature service/action that reads or writes the changed table.
- Generate or push the schema depending on environment.
- Add or update tests under
src/test. - Run
pnpm typecheckand targeted tests.
Common table areas
| Area | Used by |
|---|---|
| Auth users and sessions | Better Auth |
| Credits and transactions | Credits ledger and purchases |
| Subscriptions | Payment and plan lookup |
| Support tickets | User support and admin ticket queue |
| Newsletter | Mail subscriptions and unsubscribe state |