Database (Postgres + Drizzle)
ShipSaaS runs on plain Postgres — any provider works (Neon, Railway, Supabase, RDS, self-hosted). Drizzle is the type-safe query layer, and Better Auth owns the auth tables in the same schema. This guide covers the schema, migrations, and how to query the database.
Schema overview
The template ships with these tables:
user— the Better Auth user table. Auth fields (name,email,emailVerified,image) plus app fields likestripeCustomerId,isSubscribed, andsubscriptionTier.session,account,verification— Better Auth's session store, OAuth account links, and email-verification tokens.subscriptions— one row per active or historical subscription, keyed by(provider, providerSubscriptionId).orders— one-time payments (digital downloads, lifetime deals, etc).payments— every recurring charge or invoice, keyed byproviderPaymentIdfor idempotency.webhook_events— audit trail of every webhook received, with aprocessedflag for retry safety.waitlistandemail_log— optional (see migrations 002 and 003).
Apply the migrations
The reviewed SQL lives in migrations/ and is applied in order:
001_initial_schema.sql— Better Auth tables, app tables, enums, indexes, and thesync_user_subscription_status()trigger that flipsuser.isSubscribedbased on subscription status.002_waitlist.sql— optional pre-launch email capture table.003_email_log.sql— optional delivery-audit table.
Either apply them directly:
psql $DATABASE_URL -f migrations/001_initial_schema.sql psql $DATABASE_URL -f migrations/002_waitlist.sql psql $DATABASE_URL -f migrations/003_email_log.sql
…or let Drizzle generate and push the schema from src/db/schema.ts:
npx drizzle-kit push
Authorization model
There is no row-level security by design: the app connects with a single Postgres role and every query is scoped in application code — all database access goes through server-side code (src/db/queries.ts and route handlers); nothing queries the database from the browser.
If you add admin features, scope them explicitly in the query layer (a role column on user plus server-side checks), and keep every table's userId foreign key — user deletion cascades across session, account, subscription, order, and payment rows.
Querying with Drizzle
All queries go through src/db/queries.ts:
import { getUserById, getActiveSubscription } from "@/db/queries";
const user = await getUserById(userId);
const subscription = await getActiveSubscription(userId);
if (subscription) {
// user has an active or trialing subscription
}For one-off queries, use the Drizzle client directly:
import { db } from "@/db";
import { user } from "@/db/schema";
import { eq } from "drizzle-orm";
const [row] = await db
.select()
.from(user)
.where(eq(user.id, userId));Local development
The included docker-compose.yml starts a local Postgres 16 on port 5432. Point DATABASE_URL at it:
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/shipsaas
Run npm run db:push to apply the Drizzle schema, and npm run db:studio to open Drizzle Studio for a local GUI.