lib/db/schema.ts with 47 tables organized into functional groups. This page provides a comprehensive reference.
Schema Overview
Entity Relationships
Core Tables
Authentication & Users
user - Team Members
Internal team members who use CharleOS.
Access Levels:
- Admin: Full system access (Luke)
- Manager: Management access (Simon, Andre, Ben, Nic)
- Staff: Standard access (developers, designers, PMs, CSMs)
- development, design, qa: Individual Contributors (ICs)
- pm: Project Managers
- csm: Client Success Managers
- sdr: Sales Development Representatives
session & account
Better Auth tables for session management and OAuth accounts.
session: Active login sessions (expires after 7 days)account: OAuth provider connections (Google)
user_preference
User UI preferences (key-value store).
Client Management
client - Client Companies
Companies that hire Charle for work.
client_period - Billing Periods
Tracks budget usage per billing period (monthly).
client_deliverability_score - Scoring
Tracks how actual task times compare to quoted estimates per client.
Score interpretation:
1.00= Tasks match estimates exactly1.15= Tasks take 15% longer than quoted0.90= Tasks complete 10% faster than quoted
low(< 5 tasks): Don’t use for schedulingmedium(5-15 tasks): Use with cautionhigh(15+ tasks): Reliable for scheduling
client_score_history - Score Audit
Audit trail for score changes.
client_user - Client Portal Users
Client employees who access the client portal.
Separate Auth System:
- Client portal uses Better Auth with separate tables
client_sessionfor sessionsclient_accountfor credentials- Completely isolated from team auth
plan - Pricing Tiers
Retainer plan configurations.
Quote System
quote - Work Requests
Requests for work that go through approval workflow.
Quote Workflow:
awaiting_quote- Created, needs scopingin_progress- Being scoped by teamquoted- Ready for internal reviewawaiting_client_approval- Sent to clientapproved- Client approved (converts to task)cancelled- Client cancelled
quote_requirement - Requirement Blocks
Individual work items within a quote.
AI Suggestions: When a quote requirement is created, Alan automatically generates a t-shirt size suggestion based on the brief and client history. The suggestion is stored against the requirement for team review.
T-shirt Sizing:
- XS: 15-30 min
- S: 30-60 min
- M: 1-4 hours
- L: 4-8 hours
- XL: 8-16 hours
- XXL: 16-32 hours
- Core work (80%) rounded down
- QA/feedback budget (20%) rounded up to nearest 15 min
Task System
task - Approved Work
Work items created from approved quotes or directly.
Outlier Tasks:
Tasks that deviate significantly (>130%) from quoted can be flagged as outliers. Outliers are excluded from client deliverability score calculations to prevent anomalous tasks from skewing the data.
subtask - Task Phases
Individual work phases within a task.
Subtask Types:
Design Phase:
design- Initial design workclient_design_feedback- Feedback round
development- Build workinternal_qa_fixes- Internal QA fixesexternal_qa_fixes- Client QA fixes
internal_qa_review- Internal reviewexternal_qa_review- Client review
deployment- Deploy to production
Time Tracking
time_entry - Logged Time
Time logged against clients, tasks, and subtasks.
Projects
project - Multi-Phase Projects
Long-running projects with budgeted phases.
project_phase - Budgeted Phases
Budget allocations within a project.
Scheduling
client_block - Scheduled Work
Blocks of scheduled time on the calendar.
Metrics & Reporting
metric_snapshot - Daily Metrics
Daily snapshots of utilization, day rates, and efficiency.
Help Desk
help_desk_ticket - Support Tickets
Client support requests (converted to subtasks).
AI Suggestions: When a support ticket is created, Alan automatically generates a time estimate suggestion based on ticket content and client history. The suggestion is stored against the ticket for PM review.
help_desk_deliverability_score - Help Desk Scoring
Tracks how actual help desk ticket times compare to estimated times.
Similar to
client_deliverability_score but specifically for help desk tickets.
help_desk_score_history - Score Audit
Records changes to help desk scoring for audit purposes.
Annual Leave
annual_leave - Leave Requests
Team member leave requests and approvals.
RAG Reports
rag_report - Client Status Reports
Weekly Red/Amber/Green client health reports.
Enums Reference
User & Access
Task & Subtask
Quote
Type Inference
Drizzle automatically generates TypeScript types from the schema:Relationships
Foreign Keys
All relationships use foreign keys with appropriate cascade rules:onDelete: "cascade"- Delete children when parent is deletedonDelete: "set null"- Set to null when parent is deleted- Default: Restrict deletion if children exist
Common Joins
Modifying the Schema
1
Edit Schema File
Modify
lib/db/schema.ts to add/change tables or columns2
Test Locally
3
Verify in Studio
4
Generate Migration
5
Commit & Deploy
Commit schema + migration files. Migrations run automatically on deployment.
Related Documentation
Database Overview
Database architecture and tools
Drizzle ORM
Query syntax and patterns
Migrations
Managing schema changes