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.
55 lines
2.7 KiB
Go
55 lines
2.7 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// AssignmentPolicyV2Type defines the type of assignment policy (V2).
|
|
// Reference: Chatwoot assignment_policies_controller.rb — round_robin, fair, best_skill_match
|
|
type AssignmentPolicyV2Type string
|
|
|
|
const (
|
|
APV2TypeRoundRobin AssignmentPolicyV2Type = "round_robin"
|
|
APV2TypeFair AssignmentPolicyV2Type = "fair"
|
|
APV2TypeBestSkillMatch AssignmentPolicyV2Type = "best_skill_match"
|
|
)
|
|
|
|
// AssignmentPolicyV2 represents a V2 assignment policy for an account.
|
|
// Reference: Chatwoot app/models/assignment_policy.rb (V2 spec)
|
|
// Supports named policies with different assignment strategies, linked to inboxes via AssignmentPolicyInbox.
|
|
type AssignmentPolicyV2 struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
AccountID uint `gorm:"not null;index;uniqueIndex:idx_apv2_account_name" json:"account_id"`
|
|
Name string `gorm:"size:255;not null;uniqueIndex:idx_apv2_account_name" json:"name"`
|
|
Description string `gorm:"type:text" json:"description"`
|
|
Type AssignmentPolicyV2Type `gorm:"size:50;not null;default:round_robin" json:"type"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
|
|
Account Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
|
|
AssignmentPolicyInboxes []AssignmentPolicyInbox `gorm:"foreignKey:AssignmentPolicyID" json:"inboxes,omitempty"`
|
|
}
|
|
|
|
func (AssignmentPolicyV2) TableName() string { return "assignment_policies_v2" }
|
|
|
|
// AssignmentPolicyInbox represents the join between AssignmentPolicyV2 and Inbox.
|
|
// Each Inbox can only be associated with one AssignmentPolicyV2.
|
|
// Reference: Chatwoot app/models/assignment_policy_inbox.rb
|
|
type AssignmentPolicyInbox struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
AssignmentPolicyID uint `gorm:"not null;index" json:"assignment_policy_id"`
|
|
InboxID uint `gorm:"not null;uniqueIndex:idx_apv2_inbox_unique" json:"inbox_id"`
|
|
AccountID uint `gorm:"not null;index" json:"account_id"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
|
|
AssignmentPolicy AssignmentPolicyV2 `gorm:"foreignKey:AssignmentPolicyID" json:"assignment_policy,omitempty"`
|
|
Inbox Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
|
|
}
|
|
|
|
func (AssignmentPolicyInbox) TableName() string { return "assignment_policy_inboxes" }
|