-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathschema.prisma
427 lines (309 loc) · 10.8 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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// https://pris.ly/d/prisma-schema
// https://github.com/remix-run/indie-stack/blob/main/prisma/schema.prisma
// https://github.com/epicweb-dev/epic-stack/blob/main/prisma/schema.prisma
// https://github.com/planetscale/beam/blob/main/prisma/schema.prisma
// Visualize with https://prismaliser.app
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "fullTextSearch", "fullTextIndex", "metrics", "views"]
}
// Uncomment this to enable Prisma Docs Generator
// generator docs {
// provider = "node node_modules/prisma-docs-generator"
// }
// -----------------------------------------------------------------------------
// User
// -----------------------------------------------------------------------------
model User {
id String @id @default(cuid())
email String @unique
username String @unique
phone String? @unique // numeric string
fullname String
nickname String?
password Password?
connections Connection[]
roles Role[]
images UserImage[] // multiple user images / avatars / profile pictures
profile UserProfile?
posts Post[]
tags UserTag[]
organizedEvents Event[] @relation("EventOrganizer")
appliedEvents Event[] @relation("EventApplicant")
attendedEvents Event[] @relation("EventAttendee")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([id])
@@index([email])
@@index([username])
@@index([phone])
}
model UserProfile {
id String @id @default(cuid())
userId String @unique
user User @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
headline String?
bio String? @db.Text
links Json?
isPrimary Boolean? @default(true)
isPublic Boolean? @default(true)
modeName String? @default("DEFAULT")
sequence Int? @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([id, userId])
@@index([userId])
}
model UserTag {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // TEAM | MEMBER | ...
name String @unique // Team | Member | ...
description String? @db.Text // long description about tag
users User[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Role {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // ROOT, ADMIN, MEMBER, ...
name String @unique // Root, Admin, Member, ...
description String? @db.Text // Summary of abilities
users User[]
permissions Permission[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([symbol])
}
model Permission {
id String @id @default(cuid())
action String // create, read, update, delete
entity String // user, post, etc.
access String // own or any
description String? @db.Text // details of the permission ability
roles Role[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([action, entity, access])
}
model Password {
id String @id @default(cuid())
userId String @unique
user User @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
hash String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("UserPassword")
}
model Connection {
id String @id @default(cuid())
providerName String
providerId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@unique([providerId, providerName])
@@index([userId])
@@map("UserConnection")
}
model UserImage {
id String @id @default(cuid())
url String
altText String?
userId String
user User @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([id, userId])
@@index([userId])
}
// -----------------------------------------------------------------------------
// Post
// -----------------------------------------------------------------------------
model Post {
id String @id @default(cuid())
slug String @unique
title String @db.Text
excerpt String @db.Text
content String @db.Text // Rich HTML Text
statusId String
status PostStatus @relation(fields: [statusId], references: [id])
images PostImage[]
userId String
user User @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([slug])
@@index([statusId])
@@index([userId, updatedAt]) // Extra index for user and updatedAt
}
model PostStatus {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // DRAFT, PUBLISHED, ARCHIVED, ...
name String @unique // Draft, Published, Archived, ...
description String? @db.Text // Status definition
posts Post[]
}
model PostImage {
id String @id @default(cuid())
url String
altText String?
postId String
post Post @relation(fields: [postId], references: [id], onDelete: Cascade, onUpdate: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([postId])
}
// -----------------------------------------------------------------------------
// Event
// -----------------------------------------------------------------------------
model Event {
id String @id @default(cuid())
slug String @unique
title String @db.Text
description String @db.Text
content String? @db.Text // Rich HTML Text
url String? // Url for online or hybrid
dateTimeStart DateTime @default(now())
dateTimeEnd DateTime @default(now())
ticketCategoryId String?
tikcetCategory TicketCategory? @relation(fields: [ticketCategoryId], references: [id], onUpdate: Cascade, onDelete: Cascade)
statusId String
status EventStatus @relation(fields: [statusId], references: [id])
formatId String?
format EventFormat? @relation(fields: [formatId], references: [id], onUpdate: Cascade, onDelete: Cascade)
categoryId String?
category EventCategory? @relation(fields: [categoryId], references: [id], onUpdate: Cascade, onDelete: Cascade)
mediaId String?
media EventMedia? @relation(fields: [mediaId], references: [id], onUpdate: Cascade, onDelete: Cascade)
locationId String?
location Location? @relation(fields: [locationId], references: [id])
imageId String?
image EventImage? @relation(fields: [imageId], references: [id])
tickets Ticket[]
organizerId String
organizer User @relation("EventOrganizer", fields: [organizerId], references: [id])
applicants User[] @relation("EventApplicant")
attendees User[] @relation("EventAttendee")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([statusId])
@@index([imageId])
@@index([locationId])
@@index([formatId])
@@index([categoryId])
@@index([ticketCategoryId])
@@index([mediaId])
@@index([organizerId])
}
model EventImage {
id String @id @default(cuid())
url String
altText String?
events Event[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model EventStatus {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // DRAFT, PUBLISHED, UNLISTED, ...
name String @unique // Draft, Published, Unlisted, ...
description String? @db.Text // Status definition
events Event[]
}
model EventFormat {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // MEETUP, SEMINAR, WORKSHOP, WFC
name String @unique // Meetup, Seminar, Workshop, Work from Cafe
description String? @db.Text // Long description
events Event[]
}
model EventCategory {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // IN_PERSON, ONLINE, HYBRID
name String @unique // In Person, Online, Hybrid
description String? @db.Text // Long description
events Event[]
}
model EventMedia {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // ZOOM, GOOGLE_MEET, YOUTUBE, ...
name String @unique //Zoom, Google Meet, Youtube, ...
description String? @unique // Long description
events Event[]
}
// -----------------------------------------------------------------------------
// Location
// -----------------------------------------------------------------------------
// OFFLINE / HYBRID
model Location {
id String @id @default(cuid())
label String @db.Text
address String? @db.Text // Complete combined address
mapsUrl String? @db.Text // https://goo.gl/maps/1xABCDEF123456
lat Decimal? // Latitude -90 to 90, Example: -6.1234567
lng Decimal? // Longitude -180 to 180, Example: 106.1234567
address1 String?
address2 String?
subDistrict String?
district String?
city String?
province String?
postalCode String?
countryCode String?
events Event[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// -----------------------------------------------------------------------------
// Ticket Category
// -----------------------------------------------------------------------------
model TicketCategory {
id String @id @default(cuid())
sequence Int? @unique // 1, 2, 3, ...
symbol String @unique // FREE, PAID
name String @unique // Free, Paid
description String? @db.Text // Long description
events Event[]
}
// -----------------------------------------------------------------------------
// Ticket
// -----------------------------------------------------------------------------
model Ticket {
id String @id @default(cuid())
name String // name of ticket like student ticket, general ticket, full ticket etc
price Int
description String? @db.Text // the description about the ticket like this ticket include zoom record
eventId String?
event Event? @relation(fields: [eventId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([eventId])
}
// -----------------------------------------------------------------------------
// Examples
// -----------------------------------------------------------------------------
model Example {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Image {
id String @id @default(cuid())
url String
altText String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}