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.tssetstablesFilter: ['demeter_*'], so Drizzle Kit will never emit statements touching tables outside the namespace.- The API app (not the
@demeter/corelibrary) owns the applied-migration history inapps/demeter/api/drizzle/, so the SQL is reviewable in PRs and replayable by the test harness. - The integration harness uses a dedicated
demeter_testdatabase and replaysdrizzle/*.sqlin order, tracking applied files so re-runs are no-ops; itTRUNCATE … CASCADEs 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_testschema so the harness replays from scratch (documented in the migration strategy). - − Slightly verbose table names, but unambiguous in a shared catalog.