Files
relaticle-comments/raw/essentials/database-schema.md
github-actions[bot] acc57ac106 Deploy 1.x docs
2026-03-27 10:09:54 +00:00

8.3 KiB

Database Schema

Tables, relationships, and indexes used by the Comments package.

Tables

Five tables are created by the package migrations.

comments

The main comments table with polymorphic relationships and threading support.

<th>
  Type
</th>

<th>
  Description
</th>
<td>
  bigint
</td>

<td>
  Primary key
</td>
<td>
  string
</td>

<td>
  Polymorphic model type
</td>
<td>
  bigint
</td>

<td>
  Polymorphic model ID
</td>
<td>
  string
</td>

<td>
  Commenter model type
</td>
<td>
  bigint
</td>

<td>
  Commenter model ID
</td>
<td>
  bigint (nullable)
</td>

<td>
  Parent comment for replies
</td>
<td>
  text
</td>

<td>
  HTML comment content
</td>
<td>
  timestamp (nullable)
</td>

<td>
  When the comment was last edited
</td>
<td>
  timestamp (nullable)
</td>

<td>
  Soft delete timestamp
</td>
<td>
  timestamp
</td>

<td>
  
</td>
<td>
  timestamp
</td>

<td>
  
</td>
Column
id
commentable_type
commentable_id
user_type
user_id
parent_id
body
edited_at
deleted_at
created_at
updated_at

Indexes: (commentable_type, commentable_id, parent_id)

comment_reactions

Tracks emoji reactions per user per comment.

<th>
  Type
</th>

<th>
  Description
</th>
<td>
  bigint
</td>

<td>
  Primary key
</td>
<td>
  bigint
</td>

<td>
  Foreign key to comments
</td>
<td>
  string
</td>

<td>
  Reactor model type
</td>
<td>
  bigint
</td>

<td>
  Reactor model ID
</td>
<td>
  string
</td>

<td>
  Reaction key (e.g., <code>
    thumbs_up
  </code>
  
  )
</td>
<td>
  timestamp
</td>

<td>
  
</td>
Column
id
comment_id
user_type
user_id
reaction
created_at

Unique constraint: (comment_id, user_id, user_type, reaction)

comment_mentions

Tracks @mentioned users per comment.

<th>
  Type
</th>

<th>
  Description
</th>
<td>
  bigint
</td>

<td>
  Primary key
</td>
<td>
  bigint
</td>

<td>
  Foreign key to comments
</td>
<td>
  string
</td>

<td>
  Mentioned user model type
</td>
<td>
  bigint
</td>

<td>
  Mentioned user model ID
</td>
<td>
  timestamp
</td>

<td>
  
</td>
Column
id
comment_id
user_type
user_id
created_at

Unique constraint: (comment_id, user_id, user_type)

comment_subscriptions

Tracks which users are subscribed to comment threads on specific models.

<th>
  Type
</th>

<th>
  Description
</th>
<td>
  bigint
</td>

<td>
  Primary key
</td>
<td>
  string
</td>

<td>
  Subscribed model type
</td>
<td>
  bigint
</td>

<td>
  Subscribed model ID
</td>
<td>
  string
</td>

<td>
  Subscriber model type
</td>
<td>
  bigint
</td>

<td>
  Subscriber model ID
</td>
<td>
  timestamp
</td>

<td>
  
</td>
Column
id
commentable_type
commentable_id
user_type
user_id
created_at

Unique constraint: (commentable_type, commentable_id, user_type, user_id)

comment_attachments

Stores file attachment metadata for comments.

<th>
  Type
</th>

<th>
  Description
</th>
<td>
  bigint
</td>

<td>
  Primary key
</td>
<td>
  bigint
</td>

<td>
  Foreign key to comments
</td>
<td>
  string
</td>

<td>
  Path on the storage disk
</td>
<td>
  string
</td>

<td>
  Original uploaded filename
</td>
<td>
  string
</td>

<td>
  File MIME type
</td>
<td>
  bigint
</td>

<td>
  File size in bytes
</td>
<td>
  string
</td>

<td>
  Laravel filesystem disk
</td>
<td>
  timestamp
</td>

<td>
  
</td>
<td>
  timestamp
</td>

<td>
  
</td>
Column
id
comment_id
file_path
original_name
mime_type
size
disk
created_at
updated_at

Relationships

Commentable Model (e.g., Project)
  └── comments (morphMany)
        ├── user (morphTo → User)
        ├── parent (belongsTo → Comment)
        ├── replies (hasMany → Comment)
        ├── reactions (hasMany → CommentReaction)
        ├── attachments (hasMany → CommentAttachment)
        └── mentions (morphToMany → User)

All relationships are polymorphic, allowing the same comment system to work across any number of models in your application.