-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathschema.prisma
More file actions
executable file
·171 lines (153 loc) · 4.94 KB
/
schema.prisma
File metadata and controls
executable file
·171 lines (153 loc) · 4.94 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
// 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 YDocSnapshot {
id String @id
createdAt DateTime @default(now())
message String?
yDocBlob Bytes
repo Repo @relation(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")
yDocBlob Bytes?
yDocSnapshots YDocSnapshot[]
}
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")
}