# db

Postgres schema and durable state: responsibilities, supported exports and extension points.

## Purpose [#purpose]

Drizzle tables and relations describe auth and application state. The package owns connection lifetimes, migrations, audit/outbox writes, Organization provisioning and scheduled-job leases. Enum subpaths are client-safe leaves.

## Public exports [#public-exports]

| Subpath | Target |
| --- | --- |
| `.` | `./src/index.ts` |
| `./audit` | `./src/audit.ts` |
| `./relations` | `./src/relations.ts` |
| `./schema` | `./src/schema/index.ts` |
| `./schema/auth` | `./src/schema/auth.ts` |
| `./schema/audit` | `./src/schema/audit.ts` |
| `./schema/todo` | `./src/schema/todo.ts` |
| `./schema/flags` | `./src/schema/flags.ts` |
| `./schema/todo.enums` | `./src/schema/todo.enums.ts` |
| `./schema/flags.enums` | `./src/schema/flags.enums.ts` |
| `./schema/proposals` | `./src/schema/proposals.ts` |
| `./schema/webhooks` | `./src/schema/webhooks.ts` |
| `./schema/webhooks.enums` | `./src/schema/webhooks.enums.ts` |
| `./schema/proposals.enums` | `./src/schema/proposals.enums.ts` |
| `./provision-organization` | `./src/provision-organization.ts` |
| `./schema/jobs` | `./src/schema/jobs.ts` |
| `./job-db` | `./src/job-db.ts` |
| `./schema/uploads` | `./src/schema/uploads.ts` |
| `./schema/uploads.enums` | `./src/schema/uploads.enums.ts` |
| `./schema/billing` | `./src/schema/billing.ts` |
| `./schema/notifications` | `./src/schema/notifications.ts` |
| `./schema/notifications.enums` | `./src/schema/notifications.enums.ts` |
| `./schema/imports` | `./src/schema/imports.ts` |
| `./schema/imports.enums` | `./src/schema/imports.enums.ts` |
| `./schema/assistant` | `./src/schema/assistant.ts` |
| `./schema/documents` | `./src/schema/documents.ts` |
| `./schema/documents.enums` | `./src/schema/documents.enums.ts` |

These paths come from `packages/db/package.json`. A `.` entry is the package root. Conditional targets distinguish platform or type resolution; consumers should import the subpath, not its source file.

## How to extend [#how-to-extend]

Generate and review a journaled migration. Register needed relations in the schema aggregate. Keep enum values in import-free leaves and scope domain rows by Organization. Use transactions for domain changes and their audit/outbox records.

Read the [postgres schema and durable state guide](/docs/features/database) for the full flow.

## Key files [#key-files]

- [`packages/db/package.json`](https://github.com/CarlosZiegler/doro/blob/main/packages/db/package.json)

