// Real Estate Agent Platform - Database Schema // Milestone 1: Foundation & Authentication 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? // 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 // Basic Info firstName String? lastName String? phone String? avatar String? bio String? headline String? // Location city String? state String? country String? address String? // Professional Info yearsOfExperience Int? licenseNumber String? companyName String? // Profile Status isProfileComplete Boolean @default(false) profileCompleteness Int @default(0) // Timestamps createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // Relations user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@index([userId]) @@index([slug]) @@index([city, state]) @@map("agent_profiles") } // =========================================== // 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") }