Database Design
PostgreSQL schema, Drizzle ORM patterns, and pgvector usage.
Database Design
Linea uses PostgreSQL with the pgvector extension for vector similarity search. The ORM is Drizzle, which generates type-safe queries from the schema.
Schema Packages
The schema lives in packages/db/src/schema/. Each file owns one domain:
| File | Tables |
|---|---|
users.ts | users |
workspaces.ts | workspaces, workspace_members, workspace_invites, audit_logs |
spaces.ts | spaces |
workflows.ts | workflows |
executions.ts | executions, execution_steps |
operations.ts | schedules, webhooks, notifications |
integrations.ts | api_keys, secrets, linea_api_keys |
mcp.ts | mcp_servers, mcp_tools |
memory.ts | memories, memory_sessions, knowledge_bases, knowledge_entries |
resources.ts | resource_pools, resource_quotas, resource_usage |
pgvector
packages/db/src/schema/_vector.ts defines a shared custom Drizzle type:
Used on memories.embedding and knowledge_entries.embedding (both 1536-dim, matching text-embedding-3-small).
Cosine Similarity Queries
Drizzle doesn't natively support the <=> pgvector operator. Use sql template tags:
The result of db.execute() with the postgres-js driver is a RowList which extends ReadonlyArray. Iterate it directly; there is no .rows property.
Drizzle Patterns
Soft Delete
workflows.deletedAt: null means active, non-null means trashed. Use isNull / isNotNull from drizzle-orm:
Conflict Resolution (Memories)
memories.supersededById is a self-referential UUID (no FK constraint; avoids Drizzle circular reference issues). When a new memory supersedes an old one, the old row's supersededById is set to the new row's ID. All queries exclude superseded rows with isNull(memories.supersededById).
Relations
Drizzle relations() declarations are used for type inference only; they don't affect the runtime SQL. All actual JOINs are written explicitly in service methods.
Migrations
Schema changes are applied with:
db:push has been used throughout development. Before going to production, switch to db:generate + db:migrate to maintain a migration history.