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)
- Set the DB URL in
.env:
DATABASE_URL=postgres://user:password@host:port/dbname- Push schema to the DB:
bun run db:pushDone. 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)
| Task | Command |
|---|---|
| Push schema changes to the database | bun run db:push |
| Generate new migration files | bun run db:generate |
| Add a new table | Create the file, then run bun run db:push |
Adding New Tables (Workflow)
- Create your schema file:
src/features/yourfeature/yourfeature.schema.ts - Export the new tables using Drizzle's
pgTable(). - Export that file from
src/features/database/schema.ts. - 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
.envto version control. Ever. - For production, use migrations (
db:generate) for schema changes.db:pushis for dev/testing.