Complete reference for the current PostgreSQL schema as of July 2026. Source of truth: database/prisma/schema.prisma in the Metiss-AI/orion repo.
Status
AS-IS — current state
Models
27 models across 6 domains
Database
PostgreSQL 16 · Cloud SQL
Version
v1.0 — 2026-07-08
AS-ISData ModelPostgreSQLPrisma
Schema file:database/prisma/schema.prisma in Metiss-AI/orion. Issues in this model are tracked in the Data Model Execution Plan. Background and rationale in the Architecture Review.
01Domain map
27 models across 6 domains. Dashed arrows indicate foreign key direction (child → parent).
02Auth domain
User
Central identity record. All audit trails and assignments reference this model.
Field
Type
Notes
id
UUID (PK)
Primary key
firstName, lastName
VarChar(80)
name
VarChar(120)
Computed full name — redundant with first+last
email
VarChar(255) UNIQUE
role
String→ enum DM-02
"Executive" | "Admin" | "Project Coordinator"
status
String→ enum DM-02
"Active" | "Inactive" | "Suspended"
communicationPreference
String→ enum DM-02
"Email" | "Text Message"
passwordHash
VarChar(255)
bcrypt hash
invalidLoginAttempts
Int default 0
Incremented on failed login
jobTitle, phoneNumber, avatarUrl
VarChar / nullable
createdAt, updatedAt
Timestamptz
Session
Field
Type
Notes
id
UUID (PK)
tokenHash
VarChar(255) UNIQUE
HTTP-only cookie value, hashed
userId
UUID → User
Cascade delete on user removal
expiresAt
Timestamptz
Indexed
revokedAt
Timestamptz?
Null = active session
ForgotPasswordToken
Field
Type
Notes
id
BigInt (PK autoincrement)
uuid
UUID UNIQUE
Exposed in reset URL
tokenHash
VarChar(255) UNIQUE
One-time reset token, hashed
userId
UUID → User
Cascade delete
expiresAt, usedAt
Timestamptz
usedAt set when consumed
03Jobs domain
Job
The central operational record. Every field service assignment starts here.
Field
Type
Notes
id
UUID (PK)
jobId
VarChar(80) UNIQUE
Human-readable identifier (e.g. ORN-00123)
partnerId
UUID → Partner
Required — which partner owns this job
userId
UUID → User?
Assigned Metiss team member
organizationId
BigInt → Organization?See DM-07
Subcontractor FK
subContractor
String?DM-07: deprecate
Legacy free-text subcontractor name; coalesced with org.name
Proper FK — counterpart to the emailThreadIds array
isRead
Boolean default false
lastActivityAt
Timestamptz
EmailMessage
Field
Type
Notes
id
BigInt (PK autoincrement)
uuid
UUIDDM-09: add @unique
@default(uuid()) present but @unique missing
threadId
BigInt → EmailThread
Cascade delete
messageId
String? UNIQUE
SMTP Message-ID header
inReplyTo
String?
SMTP In-Reply-To header
references
String[]
SMTP References header
direction
Direction enum
SENT | RECEIVED
fromEmail
String
toEmails, ccEmails, bccEmails
String[]
subject
String
bodyHtml
String?
attachmentsGroupId
UUID?
Groups attachments across messages
receivedAt
Timestamptz
Indexed with threadId
07System domain
EventLog
Local event store. Used when EVENT_PUBLISHER_DRIVER=local. In production, domain mutations should publish to GCP Pub/Sub instead — see Architecture Review §4.4.
Field
Type
Notes
id
UUID (PK)
eventType, aggregateType
VarChar(80)
aggregateId
UUID
ID of the entity that changed
provider
VarChar(60)
"local" | "gcp-pubsub"
status
VarChar(60)
payloadJson
String
Full event payload as JSON string
AuditLog
Field
Type
Notes
id
BigInt (PK autoincrement)
schemaName, tableName
VarChar(120)
entityId, entityUuid
BigInt? / UUID?
Indexed with tableName
operation
VarChar(120)
"INSERT" | "UPDATE" | "DELETE"
version
Int
Monotonic version counter per entity
after
Json?
Snapshot of row after mutation
SavedSearch
Field
Type
Notes
id
BigInt (PK autoincrement)
uuid
UUID UNIQUE
view
VarChar(32) default 'active'
Which job board tab this search applies to
name
VarChar(120)
searchCriteria
Text
JSON-serialised filter state
shareSettings
VarChar(255)?
selectedUserIds
String[]
Users the search is shared with
createdByUserId, updatedByUserId
UUID → User
isDeleted
Boolean default false
SavedSearchHistory mirrors SavedSearch in the history schema with a composite PK of (id, version) — populated by a PostgreSQL trigger on every update to track change history. Its uuid field carries the entity's UUID repeated across all version rows and has no @default(uuid()). The absence of @unique here is intentional — multiple rows share the same UUID by design.
08Note join tables
UserNote is a shared note body used by five entity-specific join tables. This is a parallel note system to Notes — see Architecture Review §3.4.