# ADR-0006: Shared database with a `demeter_` table namespace

**Status:** Accepted

## Context

Demeter is one domain in a larger monorepo. Depending on the deployment, its
tables may live in a database shared with other domains (or a dedicated
`demeter` database). Either way, migration tooling that "diffs the schema and
drops anything it doesn't recognise" is dangerous in a shared database — it
could delete another domain's tables.

## Decision

Namespace **every** Demeter table and enum with the `demeter_` prefix, and pin
the migration tool to that namespace:

- `drizzle.config.ts` sets `tablesFilter: ['demeter_*']`, so Drizzle Kit will
  never emit statements touching tables outside the namespace.
- The API app (not the `@demeter/core` library) owns the applied-migration
  history in `apps/demeter/api/drizzle/`, so the SQL is reviewable in PRs and
  replayable by the test harness.
- The integration harness uses a dedicated `demeter_test` database and replays
  `drizzle/*.sql` in order, tracking applied files so re-runs are no-ops; it
  `TRUNCATE … CASCADE`s between tests for isolation.

## Consequences

- **+** Safe to share a database; the migration tool is fenced to Demeter's
  tables.
- **+** Clear ownership boundary; migrations are app-owned and reviewable.
- **+** Test isolation without per-test schema rebuilds (truncate, not migrate).
- **−** Editing an already-applied migration requires resetting the
  `demeter_test` schema so the harness replays from scratch (documented in the
  [migration strategy](../../../api/docs/operations/migration-strategy.md)).
- **−** Slightly verbose table names, but unambiguous in a shared catalog.
