Skip to content

Latest commit

 

History

History
160 lines (118 loc) · 6.44 KB

File metadata and controls

160 lines (118 loc) · 6.44 KB
//////////////////////////////////////////////////////////////////////////////////////////////
// DO NOT MODIFY THIS FILE                                                                  //
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
// Source: schema.zmodel · Generated: 2026-02-23                                            //
//////////////////////////////////////////////////////////////////////////////////////////////

Index / Models / Workspace

🗃️ Workspace Model

A collaborative workspace that groups users, content, and billing.

Workspaces are the top-level tenant boundary. All content, billing, and permissions are scoped to a workspace. A user can be a member of multiple workspaces, each with a different role.

The workspace slug is used in URLs (app.example.com/:slug) and must be globally unique. Once set, it can only be changed by an OWNER — and the old slug is reserved for 30 days to prevent broken links.

Category: Identity · Since: 1.0 · Defined in: identity.zmodel


Declaration · identity.zmodel
model Workspace with Timestamps {
    id              String            @id @default(cuid())
    name            String            @length(2, 100) @meta('doc:example', 'Acme Engineering')
    slug            String            @unique @length(3, 40) @regex('^[a-z0-9][a-z0-9-]*[a-z0-9]$') @lower @meta('doc:example', 'acme-eng')
    description     String?
    logoUrl         String?           @url
    memberLimit     Int?
    isPaid          Boolean           @default(false)
    members         WorkspaceMember[]
    subscriptions   Subscription[]
    articles        Article[]
    categories      Category[]
    comments        Comment[]

    @@allow('read', members?[user == auth()])
    @@allow('update', members?[role == 'OWNER' || role == 'ADMIN'])
    @@deny('delete', subscriptions?[status == 'ACTIVE'])
    @@index([slug])
    @@meta('doc:category', 'Identity')
    @@meta('doc:since', '1.0')
}

On this page: Mixins · Fields · Relationships · Access Policies · Indexes · Validation Rules

🧩 Mixins

Reusable field groups mixed into this model.

📋 Fields

All fields defined on this entity, including inherited fields from mixins and parent models.

Field Type Required Default Attributes Source Description
createdAt DateTime Yes now() Timestamps When the record was first created. Immutable after insert.
updatedAt DateTime Yes @updatedAt Timestamps When the record was last modified. Updated automatically.
id String Yes cuid() @id
name String Yes @length(2, 100) Example: Acme Engineering Human-readable workspace name. Displayed in the sidebar,
page titles, and email subjects.
slug String Yes @unique, @length(3, 40), @regex('^[a-z0-9][a-z0-9-]*[a-z0-9]$'), @lower Example: acme-eng URL-safe workspace identifier used in routing.
Lowercase alphanumeric and hyphens only. Globally unique.
description String? No Optional longer description shown on the workspace settings page.
logoUrl String? No @url URL to the workspace logo. Displayed in the sidebar and
public-facing pages. Recommended size: 256x256px.
memberLimit Int? No Maximum number of members allowed. Enforced at the application
layer. Null means unlimited (enterprise plans only).
isPaid Boolean Yes false Whether the workspace is on a paid plan with active billing.
Free-tier workspaces have reduced limits on storage and members.
members WorkspaceMember[] No
subscriptions Subscription[] No
articles Article[] No
categories Category[] No
comments Comment[] No

🔗 Relationships

Foreign key relationships to other models in the schema.

Field Related Model Type
articles Article One→Many
categories Category One→Many
comments Comment One→Many
members WorkspaceMember One→Many
subscriptions Subscription One→Many

diagram

🔐 Access Policies

ZenStack access control rules that determine who can read, create, update, or delete records.

Important

Operations are denied by default. @@allow rules grant access; @@deny rules override any allow.

Operation Rule Effect
read members?[user == auth()] Allow
update `members?[role == 'OWNER'
delete subscriptions?[status == 'ACTIVE'] Deny

📇 Indexes

Database indexes defined on this model for query performance.

Fields Type
[slug] Index

✅ Validation Rules

Field-level and model-level validation constraints enforced at the ORM layer.

Field Rule
name @length
slug @length
slug @regex
slug @lower
logoUrl @url

📚 References


Previous: User · Next: WorkspaceMember