# 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`           |
| `./tenancy`                          | `./src/tenancy.ts`                          |
| `./schema/workspace`                 | `./src/schema/workspace.ts`                 |
| `./schema/workspace.enums`           | `./src/schema/workspace.enums.ts`           |
| `./schema/support`                   | `./src/schema/support.ts`                   |
| `./schema/support.enums`             | `./src/schema/support.enums.ts`             |
| `./schema/harness`                   | `./src/schema/harness.ts`                   |
| `./schema/harness.enums`             | `./src/schema/harness.enums.ts`             |
| `./schema/elefant`                   | `./src/schema/elefant.ts`                   |
| `./schema/elefant.enums`             | `./src/schema/elefant.enums.ts`             |
| `./schema/harness.tool-inputs.enums` | `./src/schema/harness.tool-inputs.enums.ts` |
| `./audit-chain`                      | `./src/audit-chain.ts`                      |
| `./berlin-time`                      | `./src/berlin-time.ts`                      |
| `./seed/hasomed/accounts`            | `./src/seed/hasomed/accounts.ts`            |
| `./seed/hasomed/demo-data`           | `./src/seed/hasomed/demo-data.ts`           |
| `./seed/hasomed/elefant`             | `./src/seed/hasomed/elefant.ts`             |
| `./seed/hasomed/evals`               | `./src/seed/hasomed/evals.ts`               |
| `./seed/hasomed/fixtures`            | `./src/seed/hasomed/fixtures.ts`            |
| `./seed/hasomed/ids`                 | `./src/seed/hasomed/ids.ts`                 |
| `./seed/hasomed/practices`           | `./src/seed/hasomed/practices.ts`           |
| `./seed/hasomed/registry`            | `./src/seed/hasomed/registry.ts`            |
| `./seed/hasomed/tickets`             | `./src/seed/hasomed/tickets.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/template-cloudflare/blob/main/packages/db/package.json)

