@@ -28,6 +28,9 @@ model User {
2828 createdDocuments Document [] @relation (" DocumentCreator " )
2929 invitationsSent SpaceInvitation [] @relation (" InvitationSender " )
3030 snapshots DocumentSnapshot []
31+ activityLogs ActivityLog []
32+ documentVisits DocumentVisit []
33+ templates DocumentTemplate []
3134
3235 @@map (" users " )
3336}
@@ -47,6 +50,7 @@ model Space {
4750 documents Document []
4851 permissions SpacePermission []
4952 invitations SpaceInvitation []
53+ templates DocumentTemplate []
5054
5155 @@index ([ownerId ] )
5256 @@index ([isPublic ] )
@@ -75,6 +79,7 @@ model Document {
7579 creator User @relation (" DocumentCreator " , fields : [createdBy ] , references : [id ] )
7680 shareLinks ShareLink []
7781 snapshots DocumentSnapshot []
82+ visits DocumentVisit []
7883
7984 @@index ([spaceId ] )
8085 @@index ([parentId ] )
@@ -169,6 +174,72 @@ enum Permission {
169174 WRITE // 可写
170175}
171176
177+ // ==================== 活动日志模型 ====================
178+ model ActivityLog {
179+ id String @id @default (cuid () )
180+ userId String
181+ action ActivityAction
182+ entityType EntityType
183+ entityId String
184+ entityName String ? // 冗余存储实体名称,避免关联查询(实体删除后仍可显示)
185+ spaceId String ? // 冗余存储,方便按空间查询
186+ spaceName String ? // 冗余存储空间名称
187+ metadata String ? @db.Text // JSON 额外信息(如旧标题、变更字段等)
188+ createdAt DateTime @default (now () )
189+
190+ // 关系
191+ user User @relation (fields : [userId ] , references : [id ] , onDelete : Cascade )
192+
193+ @@index ([userId , createdAt (sort : Desc ) ] )
194+ @@index ([spaceId , createdAt (sort : Desc ) ] )
195+ @@index ([entityType , entityId ] )
196+ @@map (" activity_logs " )
197+ }
198+
199+ // 活动动作枚举
200+ enum ActivityAction {
201+ CREATE
202+ UPDATE
203+ DELETE
204+ VIEW
205+ MOVE
206+ RESTORE
207+ SHARE
208+ JOIN
209+ LEAVE
210+ INVITE
211+ ROLE_CHANGE
212+ }
213+
214+ // 实体类型枚举
215+ enum EntityType {
216+ DOCUMENT
217+ SPACE
218+ SNAPSHOT
219+ SHARE_LINK
220+ MEMBER
221+ }
222+
223+ // ==================== 最近访问模型(独立优化表) ====================
224+ model DocumentVisit {
225+ id String @id @default (cuid () )
226+ userId String
227+ documentId String
228+ spaceId String // 冗余存储,方便查询
229+ visitCount Int @default (1 )
230+ lastVisitAt DateTime @default (now () )
231+ createdAt DateTime @default (now () )
232+
233+ // 关系
234+ user User @relation (fields : [userId ] , references : [id ] , onDelete : Cascade )
235+ document Document @relation (fields : [documentId ] , references : [id ] , onDelete : Cascade )
236+
237+ @@unique ([userId , documentId ] )
238+ @@index ([userId , lastVisitAt (sort : Desc ) ] )
239+ @@index ([spaceId ] )
240+ @@map (" document_visits " )
241+ }
242+
172243// ==================== 版本历史快照模型 ====================
173244model DocumentSnapshot {
174245 id String @id @default (cuid () )
@@ -184,3 +255,43 @@ model DocumentSnapshot {
184255 @@index ([docId , createdAt ] )
185256 @@map (" document_snapshots " )
186257}
258+
259+ // ==================== 文档模板模型 ====================
260+ model DocumentTemplate {
261+ id String @id @default (cuid () )
262+ name String
263+ description String ?
264+ content String @db.Text
265+ icon String @default (" 📄" )
266+ category TemplateCategory @default (OTHER )
267+ scope TemplateScope @default (SYSTEM )
268+ spaceId String ?
269+ createdBy String
270+ sortOrder Int @default (0 )
271+ isActive Boolean @default (true )
272+ createdAt DateTime @default (now () )
273+ updatedAt DateTime @updatedAt
274+
275+ creator User @relation (fields : [createdBy ] , references : [id ] )
276+ space Space ? @relation (fields : [spaceId ] , references : [id ] , onDelete : Cascade )
277+
278+ @@index ([scope , category ] )
279+ @@index ([spaceId ] )
280+ @@index ([createdBy ] )
281+ @@map (" document_templates " )
282+ }
283+
284+ enum TemplateScope {
285+ SYSTEM
286+ SPACE
287+ USER
288+ }
289+
290+ enum TemplateCategory {
291+ MEETING
292+ TECH
293+ REPORT
294+ REQUIREMENT
295+ GUIDE
296+ OTHER
297+ }
0 commit comments