HaloStack Docs
Open App
Packages

DB

The monorepo's Drizzle + Postgres data layer — the shared client, table schema, and migration history.

@halostack/db is the single data layer for the entire monorepo. Rather than letting each package open its own connection or define its own tables, everything that touches Postgres goes through this one package: the Drizzle client, the table schema, and the migration history all live here. The connection is established through the postgres driver, reading its DATABASE_URL from @halostack/env so configuration stays centralized and validated.

Importing

The package exposes a handful of subpaths through its exports map, each scoped to what you actually need. In most cases you'll reach for the top-level @halostack/db, which re-exports the client alongside every table:

The full set of public entry points:

Structure

The package is small and predictable. The client and schema are separated so that code needing only types or only the connection can import the narrowest surface.

  • src/client.ts — the postgres connection plus the Drizzle db instance (the relational query API).
  • src/schema/index.ts — the application tables (todosTable, notifications, pushSubscriptions, mediaFilesTable, and others) along with their enums.
  • src/schema/auth.ts — the better-auth tables. These are generated, so never hand-edit them; regenerate with bun run --filter @halostack/auth auth:generate instead.
  • drizzle/ — the migration SQL and snapshots, produced by drizzle-kit.

Conventions

When you change the schema, edit the files under src/schema/* (but never auth.ts, which is generated), then create a migration with bun run generate and apply it with bun run migrate. To inspect the database visually, bun run studio opens Drizzle Studio.

A couple of rules keep the data model consistent across the monorepo. Multi-tenant rows always carry both userId and organizationId foreign keys, configured with onDelete: cascade so that removing a parent cleans up its dependent rows. And, as everywhere in the codebase, the connection string comes from @halostack/env — never read process.env directly.