// 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 } // =========================================== // 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) verifiedAt DateTime? // 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]) @@index([userId]) @@index([agentTypeId]) @@index([slug]) @@index([city, state]) @@index([isVerified]) @@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[] @@index([isActive]) @@map("agent_types") } // =========================================== // 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") }