Database
SLAW uses PostgreSQL via Drizzle ORM. There are three ways to run the database.
1. Embedded PostgreSQL (default)
Zero config. If you don't set DATABASE_URL, the server starts an embedded PostgreSQL instance automatically.
pnpm dev
On first start, the server:
- Creates
~/.slaw/instances/default/db/for storage - Ensures the
slawdatabase exists - Runs migrations automatically
- Starts serving requests
Data persists across restarts. To reset: rm -rf ~/.slaw/instances/default/db.
The Docker quickstart also uses embedded PostgreSQL by default.
2. Local PostgreSQL (Docker)
For a full PostgreSQL server locally:
docker compose up -d
This starts PostgreSQL 17 on localhost:5432. Set the connection string:
cp .env.example .env
# DATABASE_URL=postgres://slaw:slaw@localhost:5432/slaw
Push the schema:
DATABASE_URL=postgres://slaw:slaw@localhost:5432/slaw \
npx drizzle-kit push
3. Hosted PostgreSQL
For production, use a hosted provider such as Supabase.
- Create a project at database.new
- Copy the connection string from Project Settings → Database
- Set
DATABASE_URLin your.env
Use the direct connection (port 5432) for migrations and the pooled connection (port 6543) for the application. If using connection pooling, disable prepared statements in the client (postgres(url, { prepare: false })).
Switching between modes
DATABASE_URL | Mode |
|---|---|
| Not set | Embedded PostgreSQL |
postgres://...localhost... | Local Docker PostgreSQL |
postgres://... (hosted) | Hosted PostgreSQL |
The Drizzle schema (packages/db/src/schema/) is the same regardless of mode.
Next steps
- Environment Variables —
DATABASE_URLand friends - Storage — where uploaded files live
- Secrets — back up the master key with your database