367 lines
11 KiB
Plaintext
367 lines
11 KiB
Plaintext
// Real Estate Agent Platform - Database Schema
|
|
// Milestone 1 & 2: Foundation, Authentication & Agent Features
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
// ===========================================
|
|
// ENUMS
|
|
// ===========================================
|
|
|
|
enum UserRole {
|
|
USER
|
|
AGENT
|
|
ADMIN
|
|
}
|
|
|
|
enum UserStatus {
|
|
ACTIVE
|
|
INACTIVE
|
|
SUSPENDED
|
|
PENDING_VERIFICATION
|
|
}
|
|
|
|
enum AuthProvider {
|
|
LOCAL
|
|
GOOGLE
|
|
FACEBOOK
|
|
TWITTER
|
|
}
|
|
|
|
enum FieldType {
|
|
TEXT // Single line text input
|
|
TEXTAREA // Multi-line text area
|
|
CHECKBOX // Single checkbox (Yes/No)
|
|
CHECKBOX_GROUP // Multiple checkboxes in grid (select multiple)
|
|
RADIO // Radio buttons (select one)
|
|
SELECT // Dropdown (select one)
|
|
MULTI_SELECT // Dropdown with multi-select
|
|
RANGE // Slider with min/max
|
|
NUMBER // Number input
|
|
DATE // Date picker
|
|
TAG_INPUT // Tag input (add custom tags)
|
|
FILE // File upload (documents, images)
|
|
REPEATER // Repeatable group of fields (e.g., certification + years)
|
|
}
|
|
|
|
enum VerificationStatus {
|
|
NONE // Agent hasn't uploaded documents
|
|
PENDING_REVIEW // Documents uploaded, awaiting admin review
|
|
APPROVED // Admin approved verification
|
|
REJECTED // Admin rejected verification
|
|
}
|
|
|
|
|
|
// ===========================================
|
|
// USER - Authentication Only
|
|
// ===========================================
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
password String? // Null for social login users
|
|
role UserRole @default(USER)
|
|
status UserStatus @default(ACTIVE)
|
|
emailVerified Boolean @default(false)
|
|
emailVerifiedAt DateTime?
|
|
avatar String? // Profile picture URL
|
|
|
|
// Social Auth
|
|
authProvider AuthProvider @default(LOCAL)
|
|
googleId String? @unique
|
|
facebookId String? @unique
|
|
twitterId String? @unique
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
lastLoginAt DateTime?
|
|
|
|
// Relations - Profile based on role
|
|
userProfile UserProfile?
|
|
agentProfile AgentProfile?
|
|
|
|
// Auth Relations
|
|
sessions Session[]
|
|
|
|
@@index([email])
|
|
@@index([role])
|
|
@@index([status])
|
|
@@map("users")
|
|
}
|
|
|
|
// ===========================================
|
|
// USER PROFILE - Normal Users
|
|
// ===========================================
|
|
|
|
model UserProfile {
|
|
id String @id @default(uuid())
|
|
userId String @unique
|
|
firstName String?
|
|
lastName String?
|
|
phone String?
|
|
avatar String?
|
|
|
|
// Location
|
|
city String?
|
|
state String?
|
|
country String?
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@map("user_profiles")
|
|
}
|
|
|
|
// ===========================================
|
|
// AGENT PROFILE - Agents/Subscribers
|
|
// ===========================================
|
|
|
|
model AgentProfile {
|
|
id String @id @default(uuid())
|
|
userId String @unique
|
|
slug String @unique
|
|
agentTypeId String?
|
|
|
|
// Basic Info
|
|
firstName String?
|
|
lastName String?
|
|
phone String?
|
|
avatar String?
|
|
bio String? @db.Text
|
|
headline String?
|
|
|
|
// Location
|
|
city String?
|
|
state String?
|
|
country String?
|
|
address String?
|
|
zipCode String?
|
|
latitude Float?
|
|
longitude Float?
|
|
|
|
// Professional Info
|
|
yearsOfExperience Int?
|
|
licenseNumber String?
|
|
companyName String?
|
|
website String?
|
|
|
|
// Social Links
|
|
facebookUrl String?
|
|
twitterUrl String?
|
|
linkedinUrl String?
|
|
instagramUrl String?
|
|
|
|
// Verification Status
|
|
isVerified Boolean @default(false)
|
|
verificationStatus VerificationStatus @default(NONE)
|
|
verificationNote String? // Admin note (rejection reason)
|
|
verifiedAt DateTime?
|
|
verifiedBy String? // Admin user ID who verified
|
|
|
|
// Profile Status
|
|
isProfileComplete Boolean @default(false)
|
|
profileCompleteness Int @default(0)
|
|
isPublic Boolean @default(true)
|
|
isFeatured Boolean @default(false)
|
|
|
|
// Stats (denormalized for performance)
|
|
totalReviews Int @default(0)
|
|
averageRating Float @default(0)
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
agentType AgentType? @relation(fields: [agentTypeId], references: [id])
|
|
fieldValues AgentProfileFieldValue[]
|
|
|
|
@@index([userId])
|
|
@@index([agentTypeId])
|
|
@@index([slug])
|
|
@@index([city, state])
|
|
@@index([isVerified])
|
|
@@index([verificationStatus])
|
|
@@index([isPublic])
|
|
@@index([isFeatured])
|
|
@@map("agent_profiles")
|
|
}
|
|
|
|
// ===========================================
|
|
// AGENT TYPE - Dynamic agent types (Professional, Lender, etc.)
|
|
// ===========================================
|
|
|
|
model AgentType {
|
|
id String @id @default(uuid())
|
|
name String @unique
|
|
description String?
|
|
icon String?
|
|
isActive Boolean @default(true)
|
|
sortOrder Int @default(0)
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
agents AgentProfile[]
|
|
agentTypeSections AgentTypeSection[]
|
|
|
|
@@index([isActive])
|
|
@@map("agent_types")
|
|
}
|
|
|
|
// ===========================================
|
|
// DYNAMIC PROFILE FIELD SYSTEM
|
|
// ===========================================
|
|
|
|
// Profile Sections - Groups of related fields
|
|
model ProfileSection {
|
|
id String @id @default(uuid())
|
|
name String // e.g., "Location", "Experience", "Specialization"
|
|
slug String @unique // URL-friendly identifier
|
|
description String?
|
|
icon String? // Icon name or URL
|
|
sortOrder Int @default(0)
|
|
isActive Boolean @default(true)
|
|
isGlobal Boolean @default(false) // If true, applies to ALL agent types
|
|
isSystem Boolean @default(false) // If true, section cannot be deleted (system default)
|
|
isRepeatable Boolean @default(false) // If true, user can add multiple entries (e.g., certifications)
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
fields ProfileField[]
|
|
agentTypeSections AgentTypeSection[]
|
|
|
|
@@index([isActive])
|
|
@@index([isSystem])
|
|
@@index([sortOrder])
|
|
@@map("profile_sections")
|
|
}
|
|
|
|
// Many-to-Many: Which sections belong to which agent types
|
|
model AgentTypeSection {
|
|
id String @id @default(uuid())
|
|
agentTypeId String
|
|
sectionId String
|
|
sortOrder Int @default(0) // Order specific to this agent type
|
|
isRequired Boolean @default(false) // Is this section required for this type
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
agentType AgentType @relation(fields: [agentTypeId], references: [id], onDelete: Cascade)
|
|
section ProfileSection @relation(fields: [sectionId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([agentTypeId, sectionId])
|
|
@@index([agentTypeId])
|
|
@@index([sectionId])
|
|
@@map("agent_type_sections")
|
|
}
|
|
|
|
// Profile Fields - Individual form fields
|
|
model ProfileField {
|
|
id String @id @default(uuid())
|
|
sectionId String
|
|
name String // e.g., "State", "Years in Business"
|
|
slug String // Unique within section: e.g., "state", "years_in_business"
|
|
fieldType FieldType
|
|
description String? // Help text shown to user
|
|
placeholder String? // Placeholder text for input
|
|
defaultValue String? // Default value (JSON for complex types)
|
|
sortOrder Int @default(0)
|
|
isActive Boolean @default(true)
|
|
isRequired Boolean @default(false)
|
|
isSearchableOnly Boolean @default(false) // If true, shown in edit form & search, but hidden on public profile
|
|
|
|
// Validation rules (JSON)
|
|
validation Json? // { min, max, minLength, maxLength, pattern, etc. }
|
|
|
|
// For SELECT, RADIO, MULTI_SELECT, CHECKBOX_GROUP
|
|
options Json? // [{ value: "...", label: "...", sortOrder: 0 }]
|
|
|
|
// For RANGE/slider
|
|
rangeConfig Json? // { min: 0, max: 100, step: 1 }
|
|
|
|
// UI Configuration
|
|
uiConfig Json? // { columns: 2, showInPreview: true, etc. }
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
section ProfileSection @relation(fields: [sectionId], references: [id], onDelete: Cascade)
|
|
fieldValues AgentProfileFieldValue[]
|
|
|
|
@@unique([sectionId, slug])
|
|
@@index([sectionId])
|
|
@@index([isActive])
|
|
@@map("profile_fields")
|
|
}
|
|
|
|
// Agent Profile Field Values - Stores actual agent data
|
|
model AgentProfileFieldValue {
|
|
id String @id @default(uuid())
|
|
agentProfileId String
|
|
fieldId String
|
|
|
|
// Value storage - use appropriate column based on field type
|
|
textValue String? @db.Text // For TEXT, TEXTAREA
|
|
numberValue Float? // For NUMBER, RANGE
|
|
booleanValue Boolean? // For single CHECKBOX
|
|
jsonValue Json? // For MULTI_SELECT, RADIO, complex data
|
|
dateValue DateTime? // For DATE
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
agentProfile AgentProfile @relation(fields: [agentProfileId], references: [id], onDelete: Cascade)
|
|
field ProfileField @relation(fields: [fieldId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([agentProfileId, fieldId])
|
|
@@index([agentProfileId])
|
|
@@index([fieldId])
|
|
@@map("agent_profile_field_values")
|
|
}
|
|
|
|
// ===========================================
|
|
// SESSION - JWT Token Management
|
|
// ===========================================
|
|
|
|
model Session {
|
|
id String @id @default(uuid())
|
|
userId String
|
|
token String @unique
|
|
refreshToken String? @unique
|
|
userAgent String?
|
|
ipAddress String?
|
|
expiresAt DateTime
|
|
createdAt DateTime @default(now())
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@index([token])
|
|
@@map("sessions")
|
|
}
|