Skip to content

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.

FileWhat it controls
drizzle.config.tsTells 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.tsReads DATABASE_URL and creates the Drizzle connection

The key Drizzle config is small:

schema: "./server/database/schema/index.ts";
out: "./server/database/migrations";

If you are running PostgreSQL locally, create a database for the project:

Terminal window
createdb my-saas

Or with SQL:

CREATE DATABASE "my-saas";

Then point DATABASE_URL at that database:

Terminal window
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/my-saas

For a fresh install, you normally run migrations. You do not generate new ones yet.

Terminal window
pnpm db:migrate

This 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:

Terminal window
pnpm dev

Then verify these basics:

  1. the homepage loads
  2. /register opens without server errors
  3. you can create a user
  4. 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:

Terminal window
pnpm db:studio

This opens Drizzle Studio and is useful for checking:

  • users and sessions
  • organizations and memberships
  • billing tables after webhook tests

Only generate migrations after you change the schema.

Terminal window
pnpm db:generate

Use this workflow:

  1. edit schema files in server/database/schema/
  2. generate a migration
  3. review the generated SQL
  4. run the migration locally