workspace_id foreign key, making the Workspace the primary security and tenancy primitive.
Read access today: this object is readable via the universal
POST /v1/records/query endpoint with root: "workspaces". A dedicated GET /v1/workspaces endpoint is Planned.API operations
Data model
Attributes
Relationships
System-computed
- workspace_id is generated via gen_random_uuid() as a Postgres DEFAULT on insert; the application layer also sets randomUUID() as the JS default, so no manual assignment is needed at any layer.
- created_at is set by an ORM onCreate lifecycle hook to new Date() on first persist. Never updated.
- updated_at is set by both onCreate and onUpdate lifecycle hooks — it reflects the timestamp of the most recent ORM flush touching any column.
- deleted_at is null on active workspaces. Soft-deletion sets this field; every downstream query must filter deleted_at IS NULL. Hard deletes never occur.
- external_workspace_id carries a unique constraint and serves as a stable deduplication key for partner/external integrations. When provided during workspace creation, it prevents duplicate workspace provisioning for the same external customer.
- parent_workspace_pk is covered by a partial index idx_workspaces_parent filtered to WHERE parent_workspace_pk IS NOT NULL. This index is non-trivial only when the hierarchy feature is in use and keeps the hot-path workspace lookup unaffected for flat tenants.
- own_company is nullable by design. When null, the provider scoring guard is a no-op and counterparty-bank discovery (Q1, Q6) falls back to fuzzy name matching against companies scoped to the workspace — never cross-workspace.
- timezone defaults to ‘UTC’ at the database level and is updated during workspace onboarding; it governs all date/time rendering, scheduler triggers, and fiscal-period boundary calculations in the platform.
- auto_extract_enabled defaults to true; the document extraction pipeline checks this flag before dispatching AI extraction tasks for newly uploaded documents.
- enrichment_config and task_config are JSONB blobs with typed TypeScript interfaces (WorkspaceEnrichmentConfig, WorkspaceTaskConfig). They are nullable at the column level; consuming services must null-check before reading nested fields.
- WorkspaceGroupWorkspace join rows reference workspaces by pk with a partial unique index (workspace_group_pk, workspace_pk) WHERE deleted_at IS NULL — soft-deleted join rows allow legal remove-then-re-add without unique-constraint collisions.
Example
apps/api/src/database/entities/Workspace.ts · domain: workspace · tier: Platform