-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.prisma
130 lines (99 loc) · 3.88 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
// https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
email String @unique
password String
bookReviews BookReview[]
authorReviews AuthorReview[]
bookPrompts BookPrompt[]
}
model Book {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
/// true iff we're able to confirm this is a real book (AI hallucination)
confirmedExists Boolean
/// the ISBN13 number of the book if confirmedExists, else hash of title+authors
isbn13 String @unique
title String
imageUrl String?
authors Author[]
bookReviews BookReview[]
bookRecommendations BookRecommendation[]
}
model Author {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
name String @unique
books Book[]
authorReviews AuthorReview[]
}
model BookReview {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
/// The user's rating of the book (1-5)
rating Int // includes constraint bounding from 1-5, inclusive
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
bookId String
}
model AuthorReview {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
/// The user's rating of the author (1-5)
rating Int // includes constraint bounding from 1-5, inclusive
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
author Author @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
}
model BookPrompt {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
/// The user defined prompt text about the book recommendations
promptText String
promptGenreId String?
promptGenre Genre? @relation("genreBookPrompts", fields: [promptGenreId], references: [id])
promptSubgenreId String?
promptSubgenre Genre? @relation("subgenreBookPrompts", fields: [promptSubgenreId], references: [id])
/// For record keeping, the AI model which generated this recommendation
aiModel String
bookRecommendations BookRecommendation[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
}
model BookRecommendation {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
/// how confident the AI was in generating this recommendation (0 to 1)
confidenceScore Decimal @db.Decimal(3, 2) // includes constraint bounding from 0-1, inclusive
/// explanation from the AI as to why this was recommended
explanation String
bookPrompt BookPrompt @relation(fields: [bookPromptId], references: [id], onDelete: Cascade)
bookPromptId String
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
bookId String
}
model Genre {
id String @id @default(cuid(2))
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
displayName String @unique
genreBookPrompts BookPrompt[] @relation("genreBookPrompts")
subgenreBookPrompts BookPrompt[] @relation("subgenreBookPrompts")
}