Skip to content

messages

Platform messages — inquiries, comments, support. Polymorphic structure (multiple message kinds in one table) with self-relation for threads.

  • ETL strategy: merge
  • PK: id

Columns

ColumnTypeDescription
idBIGINTPK.
id_tenantBIGINTFK → tenants.id.
id_parentBIGINTFK → another messages.id. When set, this message is a reply.
id_typeBIGINTStable id for the message type.
id_roleBIGINTStable id for the author's role (admin, learner, …).
statusTEXTMessage status (preserved unchanged).
typeTEXTHuman-readable type label (preserved unchanged).
roleTEXTHuman-readable role label (preserved unchanged).
messageTEXTMessage body.
created_atTIMESTAMPTZ
deleted_atTIMESTAMPTZ

id+label pairing. id_type / type and id_role / role exist together: use id_* for stable joins and filters, and type / role for human display. The string columns (status, type, role) are stored verbatim and should be treated as opaque labels.

Patterns

sql
-- Full threads (root message + replies)
WITH RECURSIVE thread AS (
    SELECT id, id_parent, message, created_at, 0 AS depth
    FROM lms.messages
    WHERE id_parent IS NULL AND deleted_at IS NULL
  UNION ALL
    SELECT m.id, m.id_parent, m.message, m.created_at, thread.depth + 1
    FROM lms.messages m
    JOIN thread ON thread.id = m.id_parent
    WHERE m.deleted_at IS NULL
)
SELECT * FROM thread ORDER BY created_at, depth;

OpenDB · Cademi LMS Data Warehouse