Skip to content

Database

AImetier uses PostgreSQL via Drizzle ORM. There are three ways to run the database.

Zero config. If you don’t set DATABASE_URL, the server starts an embedded PostgreSQL instance automatically.

Terminal window
pnpm dev

On first start, the server:

  1. Creates ~/.aimetier/instances/default/db/ for storage
  2. Ensures the aimetier database exists
  3. Runs migrations automatically
  4. Starts serving requests

Data persists across restarts. To reset: rm -rf ~/.aimetier/instances/default/db.

The Docker quickstart also uses embedded PostgreSQL by default.

For a full PostgreSQL server locally:

Terminal window
docker compose up -d

This starts PostgreSQL 17 on localhost:5432. Set the connection string:

5432/aimetier
cp .env.example .env

Push the schema:

Terminal window
DATABASE_URL=postgres://aimetier:aimetier@localhost:5432/aimetier \
npx drizzle-kit push

For production, use a hosted provider like Supabase.

  1. Create a project at database.new
  2. Copy the connection string from Project Settings > Database
  3. Set DATABASE_URL in 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:

packages/db/src/client.ts
export function createDb(url: string) {
const sql = postgres(url, { prepare: false });
return drizzlePg(sql, { schema });
}
DATABASE_URL Mode
Not set Embedded PostgreSQL
postgres://...localhost... Local Docker PostgreSQL
postgres://...supabase.com... Hosted Supabase

The Drizzle schema (packages/db/src/schema/) is the same regardless of mode.