-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathschema.prisma
More file actions
342 lines (290 loc) · 9.99 KB
/
Copy pathschema.prisma
File metadata and controls
342 lines (290 loc) · 9.99 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Prisma client generator
generator client {
provider = "prisma-client-js"
}
// Database connection configuration
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
email String @unique // Unique index for fast user lookup by email
walletAddress String? @unique @map("wallet_address") // Unique index for wallet address
role UserRole @default(USER)
roleId String? @map("role_id")
password String?
isVerified Boolean @default(false) @map("is_verified")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
properties Property[]
receivedTransactions Transaction[] @relation("UserTransactions")
userRole Role? @relation(fields: [roleId], references: [id], onDelete: SetNull)
roleChanges RoleChangeLog[]
documents Document[]
// Indexes for common query patterns
@@index([email]) // For searching users by email
@@index([walletAddress]) // For searching users by wallet address
@@index([role]) // For filtering users by role
@@index([createdAt]) // For sorting/filtering by creation date
// Consider adding an index on isVerified if you often filter by verification status
@@index([isVerified])
@@map("users")
}
model Property {
id String @id @default(cuid())
title String
description String?
location String
price Decimal
status PropertyStatus @default(DRAFT)
ownerId String @map("owner_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Valuation fields
estimatedValue Decimal? @map("estimated_value")
valuationDate DateTime? @map("valuation_date")
valuationConfidence Float? @map("valuation_confidence")
valuationSource String? @map("valuation_source")
lastValuationId String? @map("last_valuation_id")
// Property features for valuation
bedrooms Int?
bathrooms Int?
squareFootage Decimal? @map("square_footage")
yearBuilt Int? @map("year_built")
propertyType String? @map("property_type")
lotSize Decimal? @map("lot_size")
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
transactions Transaction[]
valuations PropertyValuation[]
documents Document[]
latitude Float?
longitude Float?
// Indexes for geospatial queries and filtering
@@index([latitude, longitude]) // For location-based queries
@@index([ownerId]) // For filtering properties by owner
@@index([status]) // For filtering by property status
@@index([createdAt]) // For sorting/filtering by creation date
@@index([location]) // For searching/filtering by location
// Consider adding an index on price if you often filter/sort by price
@@index([price])
@@map("properties")
}
model PropertyValuation {
id String @id @default(cuid())
propertyId String @map("property_id")
estimatedValue Decimal @map("estimated_value")
confidenceScore Float @map("confidence_score")
valuationDate DateTime @map("valuation_date")
source String
marketTrend String? @map("market_trend")
featuresUsed Json? @map("features_used")
rawData Json? @map("raw_data")
createdAt DateTime @default(now())
property Property @relation(fields: [propertyId], references: [id], onDelete: Cascade)
// Index for fast lookup by property and date
@@index([propertyId])
@@index([valuationDate])
@@map("property_valuations")
}
model Transaction {
id String @id @default(cuid())
fromAddress String @map("from_address")
toAddress String @map("to_address")
amount Decimal
txHash String? @map("tx_hash")
status TransactionStatus @default(PENDING)
type TransactionType
propertyId String? @map("property_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
buyerId String
sellerId String
currency String
blockchainHash String?
blockNumber Int?
confirmations Int @default(0)
escrowWallet String?
gasFee Decimal?
platformFee Decimal?
disputeReason String?
property Property? @relation(fields: [propertyId], references: [id], onDelete: SetNull)
recipient User? @relation("UserTransactions", fields: [toAddress], references: [walletAddress])
documents Document[]
// Indexes for common transaction queries
@@index([buyerId]) // For filtering by buyer
@@index([sellerId]) // For filtering by seller
@@index([fromAddress]) // For filtering by sender
@@index([toAddress]) // For filtering by recipient
@@index([status]) // For filtering by transaction status
@@index([createdAt]) // For sorting/filtering by creation date
@@index([propertyId]) // For filtering by property
// Consider adding an index on txHash if you often search by transaction hash
@@index([txHash])
@@map("transactions")
}
model Role {
id String @id @default(cuid())
name String @unique
description String?
level Int @default(0)
isSystem Boolean @default(false) @map("is_system")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
users User[]
permissions RolePermission[]
roleChangeLogs RoleChangeLog[]
@@map("roles")
}
model Permission {
id String @id @default(cuid())
resource String
action String
description String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
roles RolePermission[]
@@unique([resource, action])
@@map("permissions")
}
model RolePermission {
id String @id @default(cuid())
roleId String @map("role_id")
permissionId String @map("permission_id")
createdAt DateTime @default(now()) @map("created_at")
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
permission Permission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
@@unique([roleId, permissionId])
@@map("role_permissions")
}
model RoleChangeLog {
id String @id @default(cuid())
userId String @map("user_id")
roleId String @map("role_id")
oldRoleId String? @map("old_role_id")
changedBy String? @map("changed_by")
reason String?
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
@@map("role_change_logs")
}
model AuditLog {
id String @id @default(cuid())
tableName String @map("table_name")
operation String
oldData Json? @map("old_data")
newData Json? @map("new_data")
userId String? @map("user_id")
timestamp DateTime @default(now())
@@map("audit_logs")
}
model SystemLog {
id String @id @default(cuid())
logLevel String @map("log_level")
message String
context String?
timestamp DateTime @default(now())
@@map("system_logs")
}
enum UserRole {
ADMIN
AGENT
SELLER
BUYER
VIEWER
USER
VERIFIED_USER
}
enum PropertyStatus {
DRAFT
PENDING
APPROVED
LISTED
SOLD
REMOVED
PUBLISHED
}
enum TransactionStatus {
PENDING
PROCESSING
COMPLETED
FAILED
CANCELLED
ESCROW_FUNDED
BLOCKCHAIN_SUBMITTED
CONFIRMING
CONFIRMED
DISPUTED
REFUNDED
}
enum TransactionType {
PURCHASE
TRANSFER
ESCROW
REFUND
}
enum DocumentType {
TITLE_DEED
OWNERSHIP_CERTIFICATE
INSPECTION_REPORT
APPRAISAL
INSURANCE
TAX_DOCUMENT
CONTRACT
IDENTITY
OTHER
}
enum DocumentStatus {
PENDING
VERIFIED
REJECTED
EXPIRED
}
model Document {
id String @id @default(cuid())
name String
type DocumentType
status DocumentStatus @default(PENDING)
fileUrl String @map("file_url")
fileHash String? @map("file_hash")
mimeType String? @map("mime_type")
fileSize Int? @map("file_size")
description String?
propertyId String? @map("property_id")
transactionId String? @map("transaction_id")
uploadedById String @map("uploaded_by_id")
verifiedAt DateTime? @map("verified_at")
expiresAt DateTime? @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
property Property? @relation(fields: [propertyId], references: [id], onDelete: SetNull)
transaction Transaction? @relation(fields: [transactionId], references: [id], onDelete: SetNull)
uploadedBy User @relation(fields: [uploadedById], references: [id], onDelete: Cascade)
@@index([propertyId])
@@index([transactionId])
@@index([uploadedById])
@@index([type])
@@index([status])
@@index([createdAt])
@@map("documents")
}
model ApiKey {
id String @id @default(cuid())
name String
key String @unique
keyPrefix String @map("key_prefix")
scopes String[]
requestCount BigInt @default(0) @map("request_count")
lastUsedAt DateTime? @map("last_used_at")
isActive Boolean @default(true) @map("is_active")
rateLimit Int? @map("rate_limit")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([keyPrefix])
@@index([isActive])
@@index([createdAt])
@@map("api_keys")
}