-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.prisma
More file actions
193 lines (163 loc) · 6.02 KB
/
Copy pathschema.prisma
File metadata and controls
193 lines (163 loc) · 6.02 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
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
generator zod {
provider = "zod-prisma-types"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum DeviceOS {
ios
android
web
macos
}
enum PushTokenType {
apns
fcm
}
enum ApnsEnvironment {
sandbox
production
}
model Device {
id String @id // This is a unique device id sent by the client
name String?
os DeviceOS
pushToken String? @db.Text
pushTokenType PushTokenType @default(apns)
apnsEnv ApnsEnvironment?
appVersion String?
appBuildNumber String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lastPushSuccessAt DateTime?
pushFailures Int @default(0)
identities IdentitiesOnDevice[]
}
model DeviceIdentity {
id String @id @default(uuid())
xmtpId String // This is the inboxID
identityAddress String? // Optional Identity address (for instance Turnkey address)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
profile Profile?
devices IdentitiesOnDevice[]
createdInviteCodes InviteCode[]
usedInviteCodes InviteCodeUse[]
inviteRequests InviteCodeRequest[]
notificationTargets InviteCodeNotificationTarget[]
@@unique([xmtpId])
}
model IdentitiesOnDevice {
deviceId String
device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade) // If a Device is deleted, the record linking it to an Identity is no longer valid and should be removed.
identityId String
identity DeviceIdentity @relation(fields: [identityId], references: [id], onDelete: Cascade) // If a DeviceIdentity is deleted, its presence on any device is invalidated and should be removed.
xmtpInstallationId String? @unique
@@id([deviceId, identityId])
}
model Profile {
id String @id @default(uuid())
deviceIdentityId String @unique
name String?
username String? @unique
description String?
avatar String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deviceIdentity DeviceIdentity @relation(fields: [deviceIdentityId], references: [id], onDelete: Cascade) // A Profile is intrinsically linked to a DeviceIdentity; if the identity is gone, the profile is meaningless.
}
model SubOrg {
id String @id
defaultWalletAddress String
credentialId String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum InviteCodeStatus {
ACTIVE
EXPIRED
DISABLED
}
enum InviteCodeRequestStatus {
PENDING
ACCEPTED
REJECTED
}
model GroupMetadata {
id String @id // This is the groupId
name String?
description String?
imageUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
inviteCodes InviteCode[]
}
model InviteCode {
id String @id @default(cuid())
maxUses Int? // null = unlimited uses
usesCount Int @default(0)
status InviteCodeStatus @default(ACTIVE)
expiresAt DateTime? // null = no expiration
autoApprove Boolean @default(false) // true = auto-join, false = requires approval
// Group ID to identify which group this invite code is for
groupId String
// Shared metadata reference
groupMetadata GroupMetadata @relation(fields: [groupId], references: [id])
// Keep track of who created it for admin purposes
createdById String
createdBy DeviceIdentity @relation(fields: [createdById], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
inviteCodeUses InviteCodeUse[]
inviteRequests InviteCodeRequest[]
notificationTargets InviteCodeNotificationTarget[]
@@index([status])
@@index([createdById])
@@index([groupId])
@@index([status, expiresAt])
@@index([createdById, groupId])
}
model InviteCodeUse {
id String @id @default(cuid())
inviteCodeId String
inviteCode InviteCode @relation(fields: [inviteCodeId], references: [id], onDelete: Cascade)
usedById String
usedBy DeviceIdentity @relation(fields: [usedById], references: [id], onDelete: Cascade)
usedAt DateTime @default(now())
@@unique([inviteCodeId, usedById])
@@index([inviteCodeId])
@@index([usedById])
}
model InviteCodeNotificationTarget {
id String @id @default(cuid())
inviteCodeId String
inviteCode InviteCode @relation(fields: [inviteCodeId], references: [id], onDelete: Cascade)
deviceIdentityId String
deviceIdentity DeviceIdentity @relation(fields: [deviceIdentityId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
@@unique([inviteCodeId, deviceIdentityId])
@@index([inviteCodeId])
@@index([deviceIdentityId])
}
model InviteCodeRequest {
id String @id @default(cuid())
inviteCodeId String
inviteCode InviteCode @relation(fields: [inviteCodeId], references: [id], onDelete: Cascade)
requesterId String
requester DeviceIdentity @relation(fields: [requesterId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([inviteCodeId, requesterId])
@@index([inviteCodeId])
@@index([requesterId])
@@index([inviteCodeId, createdAt])
}