-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathschema.prisma
More file actions
executable file
·210 lines (185 loc) · 5.91 KB
/
schema.prisma
File metadata and controls
executable file
·210 lines (185 loc) · 5.91 KB
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
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
generator studio-client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
model Post {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @db.VarChar(255)
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId String
}
model Profile {
id String @id
bio String?
user User @relation(fields: [userId], references: [id])
userId String @unique
}
model User {
id String @id
email String @unique
// username is an optional value, because it might create barrier when user signup.
username String? @unique
firstname String
lastname String
// A user might not have a password, if they login via OAuth.
hashedPassword String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
posts Post[]
profile Profile?
Repo Repo[] @relation("OWNER")
sharedRepos Repo[] @relation("COLLABORATOR")
stars Repo[] @relation("STAR")
UserRepoData UserRepoData[]
codeiumAPIKey String? @default("")
}
model UserRepoData {
user User @relation(fields: [userId], references: [id])
userId String
repo Repo @relation(fields: [repoId], references: [id])
repoId String
accessedAt DateTime @default(now()) @updatedAt
dummyCount Int @default(0)
// use computed ID
@@id([userId, repoId])
}
model Snapshot1 {
id String @id
createdAt DateTime @default(now())
yDocBlob Bytes?
Repo Repo @relation(fields: [repoId], references: [id])
repoId String
}
model Blob {
id String @id
updatedAt DateTime @updatedAt
yDocBlob Bytes?
Repo Repo[]
}
model Snapshot {
id String @id
createdAt DateTime @default(now())
message String?
yDocBlob Bytes?
Repo Repo? @relation(fields: [repoId], references: [id])
repoId String?
}
model UnifiedBlob {
id String @id
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
// FIXME history repo should be one repo, not a list.
yDocBlob Bytes?
history Repo[]
current Repo? @relation("HISTORY", fields: [repoId], references: [id])
repoId String?
}
model Repo {
id String @id
name String?
// fullname String @unique
owner User @relation("OWNER", fields: [userId], references: [id])
userId String
pods Pod[] @relation("BELONG")
edges Edge[]
public Boolean @default(false)
collaborators User[] @relation("COLLABORATOR")
createdAt DateTime @default(now())
// Edit pod content likely won't update this updatedAt field.
updatedAt DateTime @default(now()) @updatedAt
UserRepoData UserRepoData[]
stargazers User[] @relation("STAR")
// Option 1:
yDocBlob1 Bytes?
yDocSnapshots1 Snapshot1[]
// Option 2:
yDocBlob2 Blob? @relation(fields: [yDocBlob2Id], references: [id])
yDocBlob2Id String?
yDocSnapshots2 Snapshot[]
// Option 3:
yDocBlob3 UnifiedBlob? @relation(fields: [yDocBlob3Id], references: [id])
yDocBlob3Id String?
yDocSnapshots3 UnifiedBlob[] @relation("HISTORY")
}
enum PodType {
CODE
SCOPE
DECK
WYSIWYG
MD
REPL
}
model Edge {
source Pod @relation("SOURCE", fields: [sourceId], references: [id])
sourceId String
target Pod @relation("TARGET", fields: [targetId], references: [id])
targetId String
repo Repo? @relation(fields: [repoId], references: [id])
repoId String?
@@id([sourceId, targetId])
}
model Pod {
id String @id
parent Pod? @relation("PARENT", fields: [parentId], references: [id])
parentId String?
x Float @default(0)
y Float @default(0)
width Float @default(0)
height Float @default(0)
index Int
// TODO how to specify the order of children
//
// Option 1:
// https://stackoverflow.com/questions/11094338/storing-item-positions-for-ordering-in-a-database-efficiently
// I can store a (position, timestamp). To udpate, just move the position, and
// use a new timestamp. The newer timestamp will ensure the correct order.
//
// What about
// - addition: OK
// - deletion: OK
// - deletion + insertion: seems OK
//
//
// Option 2:
// https://softwareengineering.stackexchange.com/questions/304593/how-to-store-ordered-information-in-a-relational-database
// Another option is to maintain the order of the pod, then, update all other
// pods after it.
children Pod[] @relation("PARENT")
content String?
// the HEAD version and STAGED version of pod content
githead String?
staged String?
column Int @default(1)
fold Boolean @default(false)
thundar Boolean @default(false)
utility Boolean @default(false)
name String?
lang String?
type PodType
result String?
stdout String?
error String?
imports String?
exports String?
midports String?
reexports String?
// repo Repo? @relation("ROOT")
repo Repo @relation("BELONG", fields: [repoId], references: [id])
repoId String
// this is just a place holder. Not useful
source Edge[] @relation("SOURCE")
target Edge[] @relation("TARGET")
}