Metanow Docs
Contributing

Database

Drizzle ORM schema, running migrations, and seeding the database.

MetaNow Console uses Drizzle ORM with PostgreSQL. The pgvector extension is required for the vector similarity search that powers the learning flywheel.

Schema

The full schema lives in packages/db/src/schema.ts. The tables are:

Migrations

Migrations live in packages/db/drizzle/migrations/. They are numbered sequentially and applied in order.

pnpm db:migrate

Before running migrations on a fresh database, ensure pgvector is installed:

CREATE EXTENSION IF NOT EXISTS vector;

Adding a migration

  1. Edit packages/db/src/schema.ts.

  2. Generate the migration SQL:

    pnpm db:generate
  3. Review the generated file in packages/db/drizzle/migrations/.

  4. Apply it:

    pnpm db:migrate

Never edit a migration file that has already been applied to any environment. Create a new migration instead.

Schema helpers

packages/db/src/helpers.ts exports two column-set builders used throughout the schema:

  • orgScopedColumns(orgRef) — adds id (UUID primary key), org_id (FK to organizations), created_at, updated_at, and deleted_at (for soft deletes).
  • appendOnlyColumns(orgRef) — like orgScopedColumns but without deleted_at and updated_at. Used for immutable tables like decisions and ai_decision_trace.

Seeding

pnpm db:seed

The seed script lives at packages/db/src/seed.ts. Run it after db:migrate on a fresh local database.

Drizzle Studio

To browse the database visually:

pnpm db:studio

Injecting the database in tests

The Drizzle client is exposed via the DB injection token in NestJS. Tests can override it with a transaction client to run queries inside a rolled-back transaction, so test data never persists:

const moduleRef = await Test.createTestingModule({
  imports: [AppModule],
})
  .overrideProvider(DB)
  .useValue(transactionClient)
  .compile();

This pattern means tests run against the real schema without polluting the database.

Identity-layer data

The entities.identity and entities.fingerprint columns contain protected data. The nightly compression pipeline, which builds the cross-organization patterns, never reads the entities table: apps/server/src/queues/compression-identity-wall.spec.ts fails the build if any file on that path, or a DecisionsService method it calls, names the table. (The compression_runner role from migration 0006 holds no grants and is not used; the job runs as the application role.) fingerprint is readable but contains only structural characteristics (industry, market, entity size band), not personally identifiable information.

The platform uses no row-level security (since 2026-10-13). Tenant isolation is the org_id + platform_tenant_id filter every business query carries.

On this page