forked from sqlchat/sqlchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.prisma
162 lines (137 loc) · 5.02 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
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Ideally, we want to separate usage collection from the metadata, however Prisma does not support
// multiple databases properly. https://github.com/prisma/prisma/issues/2443 solution does not
// generate the proper client.
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
// Connection pooling URL
url = env("DATABASE_URL")
// Connection pooling is not supported by Prisma migrate yet. So need to use directUrl
directUrl = env("DATABASE_DIRECT_URL")
}
model Chat {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map("created_at")
model Json @default("{}")
ctx Json @default("{}")
messages Message[]
@@index([createdAt], map: "chat_created_at_idx")
@@map("chat")
}
model Message {
id String @id @default(cuid())
chat Chat @relation(fields: [chatId], references: [id])
chatId String @map("chat_id")
createdAt DateTime @default(now()) @map("created_at")
endUser String @default("") @map("end_user")
role String @default("")
content String @default("")
upvote Boolean @default(false)
downvote Boolean @default(false)
@@index([chatId], map: "message_chat_id_idx")
@@index([createdAt], map: "message_created_at_idx")
@@index([endUser], map: "message_end_user_idx")
@@index([role], map: "message_role_idx")
@@map("message")
}
model Usage {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map("created_at")
endUser String @default("") @map("end_user")
count Int @default(0)
@@index([createdAt], map: "usage_created_at_idx")
@@index([endUser], map: "usage_end_user_idx")
@@map("usage")
}
model Subscription {
id String @id @default(cuid())
user User @relation(fields: [userId], references: [id])
userId String @default("") @map("user_id")
// Denormalize to avoid join with the user table
email String @default("") @map("email")
createdAt DateTime @default(now()) @map("created_at")
canceledAt DateTime? @map("canceled_at")
startAt DateTime @default(now()) @map("start_at")
expireAt DateTime @default(now()) @map("expire_at")
plan SubscriptionPlan
@@index([userId], map: "subscription_user_id_idx")
@@index([email], map: "subscription_email_idx")
@@map("subscription")
}
enum SubscriptionPlan {
PRO
}
model Payment {
id String @id @default(cuid())
user User @relation(fields: [userId], references: [id])
userId String @default("") @map("user_id")
// Denormalize to avoid join with the user table
email String @default("") @map("email")
createdAt DateTime @default(now()) @map("created_at")
paymentId String @default("") @map("payment_id")
customerId String @default("") @map("customer_id")
description String @default("")
amount Int @default(0)
currency String @default("")
receipt String @default("")
@@unique([paymentId])
@@index([userId], map: "payment_user_id_idx")
@@index([email], map: "payment_email_idx")
@@map("payment")
}
// NextAuth Prisma Schema Begin
// Below are the auth related prisma schema to support NextAuth.js. In partiular, the email flow
// requires this. https://authjs.dev/reference/adapter/prisma
model Account {
id String @id @default(cuid())
userId String @map("user_id")
type String
provider String
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model Session {
id String @id @default(cuid())
sessionToken String @unique @map("session_token")
userId String @map("user_id")
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("sessions")
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime? @map("email_verified")
image String?
accounts Account[]
sessions Session[]
subscriptions Subscription[]
payments Payment[]
// The stripe customer id corresponds to this user
stripeId String? @unique @map("stripe_id")
createdAt DateTime @default(now()) @map("created_at")
@@index([createdAt], map: "users_created_at_idx")
@@map("users")
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
@@map("verificationtokens")
}
// NextAuth Prisma Schema End