Skip to content

Latest commit

 

History

History
149 lines (107 loc) · 6.09 KB

File metadata and controls

149 lines (107 loc) · 6.09 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 / Notification

🗃️ Notification Model

A notification delivered to a user.

Notifications are created by the application layer in response to events (e.g. comment on your article, workspace invitation, payment failure). They can be delivered across multiple channels based on the user's NotificationPreference settings.

Notifications are never deleted — they are marked as read and eventually archived by a background cleanup job after 90 days.

Category: Notifications · Since: 2.0 · Defined in: notifications.zmodel


Declaration · notifications.zmodel
model Notification with Timestamps {
    id          String               @id @default(cuid())
    type        String               @length(1, 80) @meta('doc:example', 'comment.created')
    title       String               @length(1, 200) @meta('doc:example', 'New comment on your article')
    body        String?
    channel     NotificationChannel  @default(IN_APP)
    severity    NotificationSeverity @default(INFO)
    read        Boolean              @default(false)
    actionUrl   String?              @url @meta('doc:example', '/articles/migrating-to-zenstack-v3#comment-abc')
    readAt      DateTime?
    recipient   User                 @relation(fields: [recipientId], references: [id])
    recipientId String

    @@allow('read', recipient == auth())
    @@allow('update', recipient == auth())
    @@deny('create,delete', true)
    @@index([recipientId, read])
    @@index([recipientId, createdAt])
    @@meta('doc:category', 'Notifications')
    @@meta('doc:since', '2.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
type String Yes @length(1, 80) Example: comment.created Machine-readable notification type for filtering and routing.
Convention: resource.event (e.g. comment.created, invoice.failed).
title String Yes @length(1, 200) Example: New comment on your article Human-readable notification title shown in the notification center.
body String? No Optional body text with additional context.
channel NotificationChannel Yes IN_APP How the notification was delivered.
severity NotificationSeverity Yes INFO Visual severity for UI treatment and delivery behavior.
read Boolean Yes false Whether the user has seen/dismissed this notification.
actionUrl String? No @url Example: /articles/migrating-to-zenstack-v3#comment-abc Deep link URL to the relevant resource in the application.
readAt DateTime? No When the user dismissed or read the notification. Null if unread.
recipient User Yes @relation(fields: [recipientId], references: [id])
recipientId String Yes

🔗 Relationships

Foreign key relationships to other models in the schema.

Field Related Model Type
recipient User Many→One

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 recipient == auth() Allow
update recipient == auth() Allow
create,delete true Deny

📇 Indexes

Database indexes defined on this model for query performance.

Fields Type
[recipientId, read] Index
[recipientId, createdAt] Index

✅ Validation Rules

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

Field Rule
type @length
title @length
actionUrl @url

📚 References


Previous: Invoice · Next: NotificationPreference