108 lines
3.4 KiB
Markdown
108 lines
3.4 KiB
Markdown
---
|
|
title: Database Schema
|
|
description: Tables, relationships, and indexes used by the Comments package.
|
|
navigation:
|
|
icon: i-lucide-database
|
|
seo:
|
|
description: Database schema reference for the Comments package.
|
|
---
|
|
|
|
## Tables
|
|
|
|
Five tables are created by the package migrations.
|
|
|
|
### comments
|
|
|
|
The main comments table with polymorphic relationships and threading support.
|
|
|
|
| Column | Type | Description |
|
|
|--------|------|-------------|
|
|
| `id` | bigint | Primary key |
|
|
| `commentable_type` | string | Polymorphic model type |
|
|
| `commentable_id` | bigint | Polymorphic model ID |
|
|
| `user_type` | string | Commenter model type |
|
|
| `user_id` | bigint | Commenter model ID |
|
|
| `parent_id` | bigint (nullable) | Parent comment for replies |
|
|
| `body` | text | HTML comment content |
|
|
| `edited_at` | timestamp (nullable) | When the comment was last edited |
|
|
| `deleted_at` | timestamp (nullable) | Soft delete timestamp |
|
|
| `created_at` | timestamp | |
|
|
| `updated_at` | timestamp | |
|
|
|
|
**Indexes:** `(commentable_type, commentable_id, parent_id)`
|
|
|
|
### comment_reactions
|
|
|
|
Tracks emoji reactions per user per comment.
|
|
|
|
| Column | Type | Description |
|
|
|--------|------|-------------|
|
|
| `id` | bigint | Primary key |
|
|
| `comment_id` | bigint | Foreign key to comments |
|
|
| `user_type` | string | Reactor model type |
|
|
| `user_id` | bigint | Reactor model ID |
|
|
| `reaction` | string | Reaction key (e.g., `thumbs_up`) |
|
|
| `created_at` | timestamp | |
|
|
|
|
**Unique constraint:** `(comment_id, user_id, user_type, reaction)`
|
|
|
|
### comment_mentions
|
|
|
|
Tracks @mentioned users per comment.
|
|
|
|
| Column | Type | Description |
|
|
|--------|------|-------------|
|
|
| `id` | bigint | Primary key |
|
|
| `comment_id` | bigint | Foreign key to comments |
|
|
| `user_type` | string | Mentioned user model type |
|
|
| `user_id` | bigint | Mentioned user model ID |
|
|
| `created_at` | timestamp | |
|
|
|
|
**Unique constraint:** `(comment_id, user_id, user_type)`
|
|
|
|
### comment_subscriptions
|
|
|
|
Tracks which users are subscribed to comment threads on specific models.
|
|
|
|
| Column | Type | Description |
|
|
|--------|------|-------------|
|
|
| `id` | bigint | Primary key |
|
|
| `commentable_type` | string | Subscribed model type |
|
|
| `commentable_id` | bigint | Subscribed model ID |
|
|
| `user_type` | string | Subscriber model type |
|
|
| `user_id` | bigint | Subscriber model ID |
|
|
| `created_at` | timestamp | |
|
|
|
|
**Unique constraint:** `(commentable_type, commentable_id, user_type, user_id)`
|
|
|
|
### comment_attachments
|
|
|
|
Stores file attachment metadata for comments.
|
|
|
|
| Column | Type | Description |
|
|
|--------|------|-------------|
|
|
| `id` | bigint | Primary key |
|
|
| `comment_id` | bigint | Foreign key to comments |
|
|
| `file_path` | string | Path on the storage disk |
|
|
| `original_name` | string | Original uploaded filename |
|
|
| `mime_type` | string | File MIME type |
|
|
| `size` | bigint | File size in bytes |
|
|
| `disk` | string | Laravel filesystem disk |
|
|
| `created_at` | timestamp | |
|
|
| `updated_at` | timestamp | |
|
|
|
|
## 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.
|