-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathschema.prisma
402 lines (341 loc) · 10.6 KB
/
schema.prisma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions", "views"]
binaryTargets = ["native"]
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
extensions = [pg_trgm]
}
generator markdown {
provider = "prisma-markdown"
title = "PROJECT"
output = "../docs/ERD.md"
}
//-----------------------------------------------------------
// ARTICLES
//-----------------------------------------------------------
/// Attachment File.
///
/// Every attachment files that are managed in current system.
///
/// For reference, it is possible to omit one of file name or extension like
/// `.gitignore` or `README` case, but not possible to omit both of them.
///
/// @namespace Articles
/// @author Samchon
model attachment_files {
//----
// COLUMNS
//----
/// @format uuid
id String @id @db.Uuid
/// File name, except extension.
///
/// If there's file `.gitignore`, then its name is an empty string.
///
/// @maxLength 255
name String @db.VarChar
/// Extension.
///
/// Possible to omit like `README` case.
///
/// @minLength 1
/// @maxLength 8
extension String? @db.VarChar
/// URL path of the real file.
///
/// @format url
url String @db.VarChar
/// Creation time of file.
///
/// @format date-time
created_at DateTime @db.Timestamptz
//----
// RELATIONS
//----
bbs_article_snapshot_files bbs_article_snapshot_files[]
bbs_article_comment_snapshots_files bbs_article_comment_snapshot_files[]
@@index([url])
}
/// Article entity.
///
/// `bbs_articles` is a super-type entity of all kinds of articles in the
/// current backend system, literally shaping individual articles of
/// the bulletin board.
///
/// And, as you can see, the elements that must inevitably exist in the
/// article, such as the title or the body, do not exist in the `bbs_articles`,
/// but exist in the subsidiary entity, {@link bbs_article_snapshots}, as a
/// 1: N relationship, which is because a new snapshot record is published
/// every time the article is modified.
///
/// The reason why a new snapshot record is published every time the article
/// is modified is to preserve the evidence. Due to the nature of e-community,
/// there is always a threat of dispute among the participants. And it can
/// happen that disputes arise through articles or comments, and to prevent
/// such things as modifying existing articles to manipulate the situation,
/// the article is designed in this structure.
///
/// In other words, to keep evidence, and prevent fraud.
///
/// @namespace Articles
/// @author Samchon
model bbs_articles {
/// @format uuid
id String @id @db.Uuid
/// Creation time of article.
created_at DateTime @db.Timestamptz
/// Deletion time of article.
///
/// To keep evidence, do not delete the article, but just mark it as
/// deleted.
deleted_at DateTime? @db.Timestamptz
//----
// RELATIONS
//----
/// List of snapshots.
///
/// It is created for the first time when an article is created, and is
/// accumulated every time the article is modified.
///
/// @minItems 1
snapshots bbs_article_snapshots[]
/// List of comments.
comments bbs_article_comments[]
mv_last mv_bbs_article_last_snapshots?
@@index([created_at])
}
/// Snapshot of article.
///
/// `bbs_article_snapshots` is a snapshot entity that contains the contents of
/// the article, as mentioned in {@link bbs_articles}, the contents of the
/// article are separated from the article record to keep evidence and prevent
/// fraud.
///
/// @namespace Articles
/// @author Samchon
model bbs_article_snapshots {
//----
// COLUMNS
//----
/// @format uuid
id String @id @db.Uuid
/// Belong article's {@link bbs_articles.id}
///
/// @format uuid
bbs_article_id String @db.Uuid
/// Format of body.
///
/// Same meaning with extension like `html`, `md`, `txt`.
format String @db.VarChar
/// Title of article.
title String @db.VarChar
/// Content body of article.
body String
/// Creation time of record.
///
/// It means creation time or update time or article.
created_at DateTime @db.Timestamptz
//----
// RELATIONS
//----
/// Belong article info.
article bbs_articles @relation(fields: [bbs_article_id], references: [id], onDelete: Cascade)
/// List of wrappers of attachment files.
to_files bbs_article_snapshot_files[]
mv_last mv_bbs_article_last_snapshots?
@@index([bbs_article_id, created_at])
@@index([title(ops: raw("gin_trgm_ops"))], type: Gin)
@@index([body(ops: raw("gin_trgm_ops"))], type: Gin)
}
/// Attachment file of article snapshot.
///
/// `bbs_article_snapshot_files` is an entity that shapes the attached files of
/// the article snapshot.
///
/// `bbs_article_snapshot_files` is a typical pair relationship table to
/// resolve the M: N relationship between {@link bbs_article_snapshots} and
/// {@link attachment_files} tables. Also, to ensure the order of the attached
/// files, it has an additional `sequence` attribute, which we will continue to
/// see in this documents.
///
/// @namespace Articles
/// @author Samchon
model bbs_article_snapshot_files {
//----
// COLUMNS
//----
/// @format uuid
id String @id @db.Uuid
/// Belonged snapshot's {@link bbs_article_snapshots.id}
///
/// @format uuid
bbs_article_snapshot_id String @db.Uuid
/// Belonged file's {@link attachment_files.id}
///
/// @format uuid
attachment_file_id String @db.Uuid
/// Sequence of attachment file in the snapshot.
///
/// @format int
sequence Int @db.Integer
//----
// RELATIONS
//----
/// Belonged article.
snapshot bbs_article_snapshots @relation(fields: [bbs_article_snapshot_id], references: [id], onDelete: Cascade)
/// Belonged file.
file attachment_files @relation(fields: [attachment_file_id], references: [id], onDelete: Cascade)
@@index([bbs_article_snapshot_id])
@@index([attachment_file_id])
}
/// Comment written on an article.
///
/// `bbs_article_comments` is an entity that shapes the comments written on an
/// article.
///
/// And for this comment, as in the previous relationship between
/// {@link bbs_articles} and {@link bbs_article_snapshots}, the content body
/// of the comment is stored in the sub {@link bbs_article_comment_snapshots}
/// table for evidentialism, and a new snapshot record is issued every time
/// the comment is modified.
///
/// Also, `bbs_article_comments` is expressing the relationship of the
/// hierarchical reply structure through the `parent_id` attribute.
///
/// @namespace Articles
/// @author Samchon
model bbs_article_comments {
//----
// COLUMNS
//----
/// @format uuid
id String @id @db.Uuid
/// Belonged article's {@link bbs_articles.id}
///
/// @format uuid
bbs_article_id String @db.Uuid
/// Parent comment's {@link bbs_article_comments.id}
///
/// Used to express the hierarchical reply structure.
///
/// @format uuid
parent_id String? @db.Uuid
/// Creation time of comment.
created_at DateTime @db.Timestamptz
/// Deletion time of comment.
///
/// Do not allow to delete the comment, but just mark it as deleted,
/// to keep evidence.
deleted_at DateTime? @db.Timestamptz
//----
// RELATIONS
//----
/// Belonged article.
article bbs_articles @relation(fields: [bbs_article_id], references: [id], onDelete: Cascade)
/// Parent comment.
///
/// Only when reply case.
parent bbs_article_comments? @relation("bbs_article_comments_reply", fields: [parent_id], references: [id], onDelete: Cascade)
/// List of children comments.
///
/// Reply comments of current.
children bbs_article_comments[] @relation("bbs_article_comments_reply")
/// List of snapshots.
///
/// It is created for the first time when a comment is created, and is
/// accumulated every time the comment is modified.
///
/// @minItems 1
snapshots bbs_article_comment_snapshots[]
@@index([bbs_article_id, parent_id, created_at])
}
/// Snapshot of comment.
///
/// `bbs_article_comment_snapshots` is a snapshot entity that contains the
/// contents of the comment.
///
/// As mentioned in {@link bbs_article_comments}, designed to keep evidence
/// and prevent fraud.
///
/// @namespace Articles
/// @author Samchon
model bbs_article_comment_snapshots {
//----
// COLUMNS
//----
/// @format uuid
id String @id @db.Uuid
/// Belonged article's {@link bbs_article_comments.id}
///
/// @format uuid
bbs_article_comment_id String @db.Uuid
/// Format of content body.
///
/// Same meaning with extension like `html`, `md`, `txt`.
format String @db.VarChar
/// Content body of comment.
body String
/// Creation time of record.
///
/// It means creation time or update time or comment.
created_at DateTime @db.Timestamptz
//----
// RELATIONS
//----
/// Belong comment info.
comment bbs_article_comments @relation(fields: [bbs_article_comment_id], references: [id], onDelete: Cascade)
/// List of wrappers of attachment files.
to_files bbs_article_comment_snapshot_files[]
@@index([bbs_article_comment_id, created_at])
@@index([body(ops: raw("gin_trgm_ops"))], type: Gin)
}
/// Attachment file of comment snapshot.
///
/// `bbs_article_comment_snapshot_files` is an entity resolving the M:N
/// relationship between {@link bbs_article_comment_snapshots} and
/// {@link attachment_files} tables.
///
/// @namespace Articles
/// @author Samchon
model bbs_article_comment_snapshot_files {
//----
// COLUMNS
//----
/// @format uuid
id String @id @db.Uuid
/// Belonged snapshot's {@link bbs_article_comment_snapshots.id}
///
/// @format uuid
bbs_article_comment_snapshot_id String @db.Uuid
/// Belonged file's {@link attachment_files.id}
///
/// @format uuid
attachment_file_id String @db.Uuid
/// Sequence order.
///
/// Sequence order of the attached file in the belonged snapshot.
///
/// @type int
sequence Int @db.Integer
//----
// RELATIONS
//----
/// Belonged article.
snapshot bbs_article_comment_snapshots @relation(fields: [bbs_article_comment_snapshot_id], references: [id], onDelete: Cascade)
/// Belonged file.
file attachment_files @relation(fields: [attachment_file_id], references: [id], onDelete: Cascade)
@@index([bbs_article_comment_snapshot_id])
@@index([attachment_file_id])
}
/// @hidden
/// @author Samchon
model mv_bbs_article_last_snapshots {
bbs_article_id String @id @db.Uuid
bbs_article_snapshot_id String @db.Uuid
article bbs_articles @relation(fields: [bbs_article_id], references: [id], onDelete: Cascade)
snapshot bbs_article_snapshots @relation(fields: [bbs_article_snapshot_id], references: [id], onDelete: Cascade)
@@unique([bbs_article_snapshot_id])
}