Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
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.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Conversation represents a conversation between a contact and agents.
|
||||
type Conversation struct {
|
||||
Base
|
||||
UUID string `gorm:"type:uuid;uniqueIndex;not null" json:"uuid"` // auto-generated global unique identifier
|
||||
DisplayID *uint `gorm:"index" json:"display_id,omitempty"` // account-level auto-increment number
|
||||
AccountID uint `gorm:"index;not null" json:"account_id"`
|
||||
InboxID uint `gorm:"index;not null" json:"inbox_id"`
|
||||
ContactID uint `gorm:"index;not null" json:"contact_id"`
|
||||
ContactInboxID *uint `gorm:"index" json:"contact_inbox_id,omitempty"`
|
||||
AssigneeID *uint `gorm:"index" json:"assignee_id"`
|
||||
AssigneeAgentBotID *uint `gorm:"index" json:"assignee_agent_bot_id,omitempty"`
|
||||
TeamID *uint `gorm:"index" json:"team_id,omitempty"`
|
||||
CampaignID *uint `gorm:"index" json:"campaign_id,omitempty"`
|
||||
SlaPolicyID *uint `gorm:"index" json:"sla_policy_id,omitempty"`
|
||||
Status string `gorm:"size:50;index;default:open" json:"status"` // open, resolved, pending, snoozed
|
||||
Priority string `gorm:"size:50;default:none" json:"priority"` // none, low, medium, high, urgent
|
||||
ChannelType string `gorm:"size:50;not null" json:"channel_type"`
|
||||
Channel string `gorm:"size:50;not null" json:"channel"` // channel identifier for routing
|
||||
Labels string `gorm:"type:text" json:"labels,omitempty"` // comma-separated or JSON label list
|
||||
SnoozedUntil *int64 `gorm:"index" json:"snoozed_until,omitempty"` // timestamp for snoozed conversations
|
||||
AdditionalAttributes datatypes.JSON `gorm:"type:jsonb" json:"additional_attributes,omitempty"`
|
||||
CustomAttributes datatypes.JSON `gorm:"type:jsonb" json:"custom_attributes,omitempty"`
|
||||
AgentLastSeenAt *int64 `json:"agent_last_seen_at,omitempty"`
|
||||
AssigneeLastSeenAt *int64 `json:"assignee_last_seen_at,omitempty"`
|
||||
ContactLastSeenAt *int64 `json:"contact_last_seen_at,omitempty"`
|
||||
WaitingSince *int64 `json:"waiting_since,omitempty"`
|
||||
LastActivityAt *int64 `json:"last_activity_at,omitempty"`
|
||||
FirstReplyCreatedAt *int64 `json:"first_reply_created_at,omitempty"`
|
||||
Muted bool `gorm:"default:false" json:"muted"`
|
||||
ResolvedAt *time.Time `json:"resolved_at,omitempty"` // Chatwoot: timestamp when conversation was resolved
|
||||
ResumedAt *time.Time `json:"resumed_at,omitempty"` // Chatwoot: timestamp when conversation was reopened
|
||||
LastMessageAt *int64 `gorm:"index" json:"last_message_at,omitempty"`
|
||||
LastNonSysMsgAt *int64 `json:"last_non_system_message_at,omitempty"`
|
||||
|
||||
Contact *Contact `gorm:"foreignKey:ContactID" json:"contact,omitempty"`
|
||||
Inbox *Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
|
||||
Assignee *User `gorm:"foreignKey:AssigneeID" json:"assignee,omitempty"`
|
||||
Messages []Message `gorm:"foreignKey:ConversationID" json:"messages,omitempty"`
|
||||
}
|
||||
|
||||
// BeforeCreate auto-generates UUID before inserting a new Conversation record.
|
||||
func (c *Conversation) BeforeCreate(tx *gorm.DB) error {
|
||||
if c.UUID == "" {
|
||||
c.UUID = uuid.New().String()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (Conversation) TableName() string { return "conversations" }
|
||||
Reference in New Issue
Block a user