Logo

Database

It's just PostgreSQL and Drizzle ORM. Type-safe and ready for production, no BS.

SaaSKit already gives you PostgreSQL and Drizzle ORM set up. Everything's pre-configured. Just drop your DATABASE_URL in, and you're good.

Setup (Two Steps)

  1. Set the DB URL in .env:
DATABASE_URL=postgres://user:password@host:port/dbname
  1. Push schema to the DB:
bun run db:push

Done. DB is live.

Database Structure

Schema Organization

Schemas are organized by feature under src/features/*/. Everything gets exported through the main file: src/features/database/schema.ts.

Examples:

  • Auth schema is at: src/features/auth/auth.schema.ts
  • New stuff goes in: src/features/yourfeature/yourfeature.schema.ts

Using the Database

The db instance is available from src/features/database/db.ts. Import it for server-side use:

// Example query
const allRoles = await db.select().from(roles);

Common Tasks (The Commands)

TaskCommand
Push schema changes to the databasebun run db:push
Generate new migration filesbun run db:generate
Add a new tableCreate the file, then run bun run db:push

Adding New Tables (Workflow)

  1. Create your schema file: src/features/yourfeature/yourfeature.schema.ts
  2. Export the new tables using Drizzle's pgTable().
  3. Export that file from src/features/database/schema.ts.
  4. Run bun run db:push.

That's all you need.

Environment Variables

Required:

  • DATABASE_URL - Gotta have your PostgreSQL connection string here.

Deployment Tip: Use a managed DB service—Railway, Supabase, Neon, whatever. They give you the secure connection strings you need.

Best Practices (I suggest you play by these rules)

  • Keep schema files with their features.
  • Never commit .env to version control. Ever.
  • For production, use migrations (db:generate) for schema changes. db:push is for dev/testing.