Pivot Database Structure - Complete ERD
1. Core Entities and Relationships
2. Notification System Detail
3. Schedule System Architecture
4. Integration System
5. Access Control & Permissions
6. Supporting Entities
7. Request System Flow
Key Relationships Summary
Primary Foreign Key Relationships:
- Users → Employees:
userId links employee records to auth accounts
- Companies → Employees:
companyId links employees to their workplace
- Users → Companies:
createdBy identifies company owners
- Employees → Schedules:
employeeId assigns shifts to workers
- Companies → All Entities: Most entities reference
companyId for multi-tenancy
- Chats → Messages:
chatId groups messages in conversations
- Employees → Positions: Complex many-to-many through position arrays
- Notifications → Requests:
requestId links notifications to their source
Index Strategy:
- Time-based queries:
createdAt, updatedAt, lastSeen, timestamp
- Relationship queries:
companyId, userId, employeeId
- Status filtering:
status, type, active
- Performance optimization: Custom indexes per entity type