Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
42 lines
2.5 KiB
Plaintext
42 lines
2.5 KiB
Plaintext
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Message represents a single message within a conversation.
|
|
// Reference: Chatwoot Message model + P2B M3 spec
|
|
type Message struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
AccountID uint `gorm:"not null;index" json:"account_id"`
|
|
InboxID uint `gorm:"not null;index" json:"inbox_id"`
|
|
ConversationID uint `gorm:"not null;index" json:"conversation_id"`
|
|
UserID *uint `gorm:"index" json:"user_id,omitempty"`
|
|
Content string `gorm:"type:text" json:"content"`
|
|
ContentType string `gorm:"size:50;not null;default:'text'" json:"content_type"` // text/input_text/input_email/image/audio/video/file/location/emoji/extended/quote/contact
|
|
MessageType string `gorm:"size:50;not null;index" json:"message_type"` // incoming/outgoing/activity/template/private
|
|
SenderType string `gorm:"size:50" json:"sender_type"` // Contact/User/AgentBot
|
|
SenderID uint `gorm:"index" json:"sender_id"`
|
|
Status string `gorm:"size:50;default:'sent'" json:"status"` // sent/delivered/read/failed
|
|
SourceID string `gorm:"size:255;index" json:"source_id"`
|
|
Private bool `gorm:"default:false" json:"private"`
|
|
External bool `gorm:"default:false" json:"external"`
|
|
AdditionalAttributes json.RawMessage `gorm:"type:jsonb" json:"additional_attributes"`
|
|
CustomAttributes json.RawMessage `gorm:"type:jsonb" json:"custom_attributes"`
|
|
InReplyTo *uint `gorm:"index" json:"in_reply_to,omitempty"`
|
|
ParentID *uint `gorm:"index" json:"parent_id,omitempty"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
Conversation Conversation `gorm:"foreignKey:ConversationID" json:"conversation,omitempty"`
|
|
Inbox Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
|
|
Sender User `gorm:"foreignKey:UserID" json:"sender,omitempty"`
|
|
Attachments []Attachment `gorm:"foreignKey:MessageID" json:"attachments,omitempty"`
|
|
Reactions []MessageReaction `gorm:"foreignKey:MessageID" json:"reactions,omitempty"`
|
|
}
|
|
|
|
func (Message) TableName() string { return "messages" } |