Parent: Chat Service


Entity Relationship Diagram

erDiagram
    assignment_customer ||--o{ chat_sessions : "participates in"
    dentist_dentist ||--o{ chat_sessions : "participates in"
    chat_sessions ||--o{ chat_messages : "contains"
    assignment_customer ||--o{ customer_notification_mapping : "has"

    assignment_customer {
        int id PK
        string email
        string name
        string cognito_sub
    }

    dentist_dentist {
        int id PK
        string email
        string name
    }

    chat_sessions {
        int id PK
        int customer_id FK
        int dentist_id FK
        datetime created_at
        datetime updated_at
        enum status
    }

    chat_messages {
        int id PK
        int session_id FK
        enum sender_type
        int sender_id
        text content
        json image_urls
        datetime created_at
        bool is_read
        datetime read_at
    }

    customer_notification_mapping {
        int id PK
        int customer_id FK
        string onesignal_player_id
        datetime created_at
        datetime updated_at
    }

Database Overview

The Chat Service uses a dual-database architecture:

DatabasePurposeAccess
PostgreSQLChat data (sessions, messages, notifications)Read/Write
MySQL (Jarvis)User data (customers, dentists)Read-only

PostgreSQL Tables (Chat Service)

chat_sessions

Represents a chat conversation between a customer and a dentist.

FieldTypeNotes
idintPrimary key
customer_idintFK to assignment_customer (MySQL)
dentist_idintFK to dentist_dentist (MySQL)
created_atdatetimeWhen the session was created
updated_atdatetimeLast activity timestamp
statusenumactive, archived

chat_messages

Individual messages within a chat session.

FieldTypeNotes
idintPrimary key
session_idintFK to chat_sessions
sender_typeenumcustomer, dentist
sender_idintID of the sender (customer or dentist)
contenttextMessage text content
image_urlsjsonArray of S3 keys for attached images
created_atdatetimeWhen the message was sent
is_readboolWhether recipient has read the message
read_atdatetimeWhen the message was read (null if unread)

customer_notification_mapping

Maps customers to their push notification player IDs.

FieldTypeNotes
idintPrimary key
customer_idintFK to assignment_customer (MySQL)
onesignal_player_idstringOneSignal player ID for push notifications
created_atdatetimeRecord creation time
updated_atdatetimeLast update time

MySQL Tables (Jarvis - Read-only)

assignment_customer

Customer information from the Jarvis system.

FieldTypeNotes
idintPrimary key
emailstringCustomer email address
namestringCustomer name
cognito_substringAWS Cognito subject identifier

dentist_dentist

Dentist information from the Jarvis system.

FieldTypeNotes
idintPrimary key
emailstringDentist email address
namestringDentist name

Indexes

Key indexes for query performance:

  • chat_sessions.customer_id - Find all chats for a customer
  • chat_sessions.dentist_id - Find all chats for a dentist
  • chat_sessions.updated_at - Order chats by recent activity
  • chat_messages.session_id - Fetch messages for a session
  • chat_messages.created_at - Paginate messages chronologically
  • customer_notification_mapping.customer_id (unique) - Lookup notification mapping