ShiftFast Docs

Database

Drizzle schema, migrations, and connection settings.

Drizzle ORM against Postgres, using the postgres (postgres.js) driver. Schema lives in src/db/schema/ (one file per domain — today, just billing.ts), the client is src/db/index.ts, and generated migrations land in src/db/migrations/.

import { db } from '@/db'

Locally, pnpm local:up runs Postgres 17 in Docker, and pnpm db:studio opens a browser UI over your data — see Local Development.

Adding a table

Define the table in a new file under src/db/schema/ and export it from src/db/schema/index.ts. Give it an orgId column — data belongs to the organization, not the user (see Organizations).

Generate a migration from the schema change, and apply it:

pnpm db:generate
pnpm db:migrate

Commit the generated files in src/db/migrations/ with the schema change.

Build Your First Feature walks through a full example, including querying the table by orgId.

Migrations aren't applied automatically on deploy — run pnpm db:migrate against production before pushing a schema change to main. See Deployment.

DATABASE_URL vs. DIRECT_URL

  • DATABASE_URL — the pooled connection the app uses at runtime.
  • DIRECT_URL — a direct, non-pooled connection used only for migrations, which generally can't run through a connection pooler.

Locally both point at the same container. With a hosted provider, use its pooled URL for the first and its direct URL for the second.

Connection poolers

The client sets prepare: false so it works behind any connection pooler, including transaction-mode poolers such as Supabase's (port 6543), which don't support prepared statements. If yours does — Neon's pooler, Supabase's session mode, or a direct connection — you can remove it to let Postgres reuse query plans.

On this page