Spaces:
Build error
Build error
File size: 13,300 Bytes
39d82a7 | 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | // PostgreSQL 16 Schema
// Run: npx prisma migrate dev --name init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ββ Users & Auth ββ
model User {
id String @id @default(uuid()) @db.Uuid
email String @unique
emailVerified DateTime?
passwordHash String? // bcrypt/Argon2 β null for OIDC users
fullName String
phone String?
avatarUrl String?
// Multi-role support
roles UserRole[]
// OIDC identities
identities OidcIdentity[]
// Profile type (for account switching)
clientProfile ClientProfile?
vendorProfile VendorProfile?
adminProfile AdminProfile?
// Sessions
sessions Session[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime? // soft delete for GDPR
@@index([email])
@@index([deletedAt])
}
model UserRole {
id String @id @default(uuid()) @db.Uuid
userId String @db.Uuid
role Role // CLIENT | VENDOR | ADMIN
isPrimary Boolean @default(false)
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([userId, role])
@@index([userId])
}
enum Role {
CLIENT
VENDOR
ADMIN
}
model OidcIdentity {
id String @id @default(uuid()) @db.Uuid
userId String @db.Uuid
provider String // google | apple | cognito | keycloak
subject String // OIDC sub claim
idToken String?
accessToken String?
refreshToken String?
expiresAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, subject])
@@index([userId])
}
model Session {
id String @id @default(uuid()) @db.Uuid
userId String @db.Uuid
token String @unique
portal String // client | vendor | admin
ipAddress String?
userAgent String?
expiresAt DateTime
revokedAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([token])
@@index([userId, portal])
}
// ββ Client Profile ββ
model ClientProfile {
id String @id @default(uuid()) @db.Uuid
userId String @unique @db.Uuid
partnerName String?
weddingDate DateTime?
location String?
guestCount Int?
budget Decimal? @db.Decimal(12, 2)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
bookings Booking[]
shortlists Shortlist[]
workspaces Workspace[]
}
// ββ Vendor Profile ββ
model VendorProfile {
id String @id @default(uuid()) @db.Uuid
userId String @unique @db.Uuid
businessName String
categoryId String @db.Uuid
description String?
district String?
address String?
website String?
socialLinks Json? // {facebook, instagram, etc}
isVerified Boolean @default(false)
isPublished Boolean @default(false)
kycStatus KycStatus @default(PENDING)
kycSubmittedAt DateTime?
kycApprovedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
category Category @relation(fields: [categoryId], references: [id])
packages Package[]
bookings Booking[]
leads Lead[]
availability VendorAvailability[]
}
enum KycStatus {
PENDING
SUBMITTED
APPROVED
REJECTED
}
// ββ Admin Profile ββ
model AdminProfile {
id String @id @default(uuid()) @db.Uuid
userId String @unique @db.Uuid
permissions String[] // MANAGE_VENDORS | MANAGE_CONTRACTS | MANAGE_USERS | SYSTEM_ADMIN
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
// ββ Categories ββ
model Category {
id String @id @default(uuid()) @db.Uuid
name String @unique
slug String @unique
emoji String?
status ContentStatus @default(PUBLISHED)
sortOrder Int @default(0)
parentId String? @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
parent Category? @relation("CategoryHierarchy", fields: [parentId], references: [id])
children Category[] @relation("CategoryHierarchy")
vendors VendorProfile[]
}
enum ContentStatus {
DRAFT
PUBLISHED
ARCHIVED
}
// ββ Packages ββ
model Package {
id String @id @default(uuid()) @db.Uuid
vendorId String @db.Uuid
name String
description String?
price Decimal @db.Decimal(12, 2)
guestCapacity Int?
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
vendor VendorProfile @relation(fields: [vendorId], references: [id], onDelete: Cascade)
@@index([vendorId])
}
// ββ Vendor Availability ββ
model VendorAvailability {
id String @id @default(uuid()) @db.Uuid
vendorId String @db.Uuid
date DateTime @db.Date
type AvailabilityType
label String?
createdAt DateTime @default(now())
vendor VendorProfile @relation(fields: [vendorId], references: [id], onDelete: Cascade)
@@unique([vendorId, date])
@@index([vendorId, date])
}
enum AvailabilityType {
AVAILABLE
BOOKED
BLOCKED
}
// ββ Bookings ββ
model Booking {
id String @id @default(uuid()) @db.Uuid
clientId String @db.Uuid
vendorId String @db.Uuid
packageId String? @db.Uuid
status BookingStatus @default(PENDING)
idempotencyKey String @unique // prevent duplicate writes
date DateTime
guestCount Int?
notes String?
totalAmount Decimal? @db.Decimal(12, 2)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
client ClientProfile @relation(fields: [clientId], references: [id])
vendor VendorProfile @relation(fields: [vendorId], references: [id])
package Package? @relation(fields: [packageId], references: [id])
contracts Contract[]
@@index([clientId])
@@index([vendorId])
@@index([status])
}
enum BookingStatus {
PENDING
CONFIRMED
CANCELLED
COMPLETED
}
// ββ Shortlist ββ
model Shortlist {
id String @id @default(uuid()) @db.Uuid
clientId String @db.Uuid
vendorId String @db.Uuid
notes String?
createdAt DateTime @default(now())
client ClientProfile @relation(fields: [clientId], references: [id], onDelete: Cascade)
@@unique([clientId, vendorId])
@@index([clientId])
}
// ββ Workspaces (client planning) ββ
model Workspace {
id String @id @default(uuid()) @db.Uuid
clientId String @db.Uuid
name String
tasks Json? // embedded checklist items
timeline Json? // embedded timeline events
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
client ClientProfile @relation(fields: [clientId], references: [id], onDelete: Cascade)
@@index([clientId])
}
// ββ Leads ββ
model Lead {
id String @id @default(uuid()) @db.Uuid
vendorId String @db.Uuid
clientId String? @db.Uuid
name String
type String
status LeadStatus @default(NEW)
notes String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
vendor VendorProfile @relation(fields: [vendorId], references: [id])
@@index([vendorId, status])
}
enum LeadStatus {
NEW
VIEWED
QUOTED
CONVERTED
LOST
}
// ββ Reviews ββ
model Review {
id String @id @default(uuid()) @db.Uuid
vendorId String @db.Uuid
clientId String @db.Uuid
rating Int // 1-5
content String?
isFlagged Boolean @default(false)
createdAt DateTime @default(now())
vendor VendorProfile @relation(fields: [vendorId], references: [id])
@@unique([vendorId, clientId])
@@index([vendorId])
}
// ββ CONTRACTS ββ
model Contract {
id String @id @default(uuid()) @db.Uuid
bookingId String @db.Uuid
vendorId String @db.Uuid
clientId String @db.Uuid
// Contract metadata
title String
serviceType String?
totalAmount Decimal @db.Decimal(12, 2)
status ContractStatus @default(DRAFT)
version Int @default(1)
// Timestamps
sentAt DateTime?
viewedAt DateTime?
signedAt DateTime?
vendorSignedAt DateTime?
clientSignedAt DateTime?
completedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
booking Booking @relation(fields: [bookingId], references: [id])
sections ContractSection[]
versions ContractVersion[]
signatures ContractSignature[]
auditLogs ContractAuditLog[]
deliverables ContractDeliverable[]
@@index([bookingId])
@@index([vendorId, status])
@@index([clientId, status])
@@index([status])
}
enum ContractStatus {
DRAFT
SENT
VIEWED
SIGNED
ACTIVE
AMENDED
DISPUTED
COMPLETED
CANCELLED
}
model ContractSection {
id String @id @default(uuid()) @db.Uuid
contractId String @db.Uuid
sortOrder Int
title String
content String
createdAt DateTime @default(now())
contract Contract @relation(fields: [contractId], references: [id], onDelete: Cascade)
@@index([contractId])
}
model ContractDeliverable {
id String @id @default(uuid()) @db.Uuid
contractId String @db.Uuid
description String
dueDate DateTime?
quantity Int?
acceptanceCriteria String?
isCompleted Boolean @default(false)
completedAt DateTime?
createdAt DateTime @default(now())
contract Contract @relation(fields: [contractId], references: [id], onDelete: Cascade)
@@index([contractId])
}
// Immutable contract version snapshot
model ContractVersion {
id String @id @default(uuid()) @db.Uuid
contractId String @db.Uuid
version Int
reason String? // reason for amendment
snapshot Json // full frozen copy of contract + sections + deliverables
createdBy String // userId
createdAt DateTime @default(now())
contract Contract @relation(fields: [contractId], references: [id])
@@unique([contractId, version])
@@index([contractId])
}
model ContractSignature {
id String @id @default(uuid()) @db.Uuid
contractId String @db.Uuid
contractVersionId String @db.Uuid
signerId String // userId
signerRole Role
signature String? // digital signature data
ipAddress String?
userAgent String?
signedAt DateTime @default(now())
contract Contract @relation(fields: [contractId], references: [id])
contractVersion ContractVersion @relation(fields: [contractVersionId], references: [id])
@@index([contractId])
@@index([signerId])
}
// Append-only audit log β rows are NEVER updated or deleted
model ContractAuditLog {
id String @id @default(uuid()) @db.Uuid
contractId String @db.Uuid
action String // created | sent | viewed | signed | declined | amended | disputed | resolved | completed
actorId String? // userId
actorRole Role?
detail String?
metadata Json? // version diff, IP, etc
createdAt DateTime @default(now())
contract Contract @relation(fields: [contractId], references: [id])
@@index([contractId, createdAt])
}
// ββ Contract Templates (vendor-submitted, admin-approved) ββ
model ContractTemplate {
id String @id @default(uuid()) @db.Uuid
vendorId String? @db.Uuid
name String
category String
status ContentStatus @default(DRAFT) // admin approval workflow
structure Json // frozen section structure + deliverable templates
submittedAt DateTime @default(now())
approvedAt DateTime?
approvedBy String? // admin userId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
vendor VendorProfile? @relation(fields: [vendorId], references: [id])
@@index([vendorId])
@@index([status])
}
// ββ Admin Audit Log ββ
model AdminAuditLog {
id String @id @default(uuid()) @db.Uuid
adminId String @db.Uuid
action String
target String? // resource acted on
detail String?
createdAt DateTime @default(now())
@@index([adminId, createdAt])
}
// ββ Notifications ββ
model Notification {
id String @id @default(uuid()) @db.Uuid
userId String @db.Uuid
title String
body String
type String // booking | contract | review | system
isRead Boolean @default(false)
link String?
createdAt DateTime @default(now())
@@index([userId, isRead, createdAt])
}
// ββ Rate Limiting (backed by Redis; schema for reference) ββ
// Key pattern: ratelimit:{ip}:{method}:{path}:{window}
// Redis INCR + EXPIRE
|