Database Setup
NuxtBase uses PostgreSQL + Drizzle ORM. The database is not optional: authentication, organizations, billing records, audit data, and most product flows depend on it.
The good news is that the setup is straightforward. The template already ships with a schema entrypoint, generated migrations, and a migration command.
Files That Matter
Section titled “Files That Matter”| File | What it controls |
|---|---|
drizzle.config.ts | Tells Drizzle where the schema lives and where migrations are stored |
server/database/schema/ | Source schema definitions |
server/database/migrations/ | Generated SQL migrations committed with the template |
server/database/index.ts | Reads DATABASE_URL and creates the Drizzle connection |
The key Drizzle config is small:
schema: "./server/database/schema/index.ts";out: "./server/database/migrations";1. Create a PostgreSQL Database
Section titled “1. Create a PostgreSQL Database”If you are running PostgreSQL locally, create a database for the project:
createdb my-saasOr with SQL:
CREATE DATABASE "my-saas";Then point DATABASE_URL at that database:
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/my-saas2. Run the Existing Migrations
Section titled “2. Run the Existing Migrations”For a fresh install, you normally run migrations. You do not generate new ones yet.
pnpm db:migratenpm run db:migrateyarn db:migrateThis applies the committed SQL files from server/database/migrations/ to your database.
3. Start the App and Verify the Connection
Section titled “3. Start the App and Verify the Connection”After migration, boot the app:
pnpm devnpm run devyarn devThen verify these basics:
- the homepage loads
/registeropens without server errors- you can create a user
- the new user gets a default personal organization
That last point matters because the auth hooks create an initial organization for every new user.
4. Use Drizzle Studio When You Need Visibility
Section titled “4. Use Drizzle Studio When You Need Visibility”If you want a browser UI to inspect tables while developing:
pnpm db:studionpm run db:studioyarn db:studioThis opens Drizzle Studio and is useful for checking:
- users and sessions
- organizations and memberships
- billing tables after webhook tests
When to Generate a New Migration
Section titled “When to Generate a New Migration”Only generate migrations after you change the schema.
pnpm db:generatenpm run db:generateyarn db:generateUse this workflow:
- edit schema files in
server/database/schema/ - generate a migration
- review the generated SQL
- run the migration locally