Files
gochat/backend/internal/model/custom_attribute_definition.go
T
rogee aeddedf2a3 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.
2026-07-07 14:44:12 +08:00

30 lines
2.2 KiB
Go

package model
import "gorm.io/datatypes"
// CustomAttributeDefinition defines a custom attribute schema for conversations or contacts.
// Reference: Chatwoot app/models/custom_attribute_definition.rb
// Account-scoped: each definition belongs to an account and applies to either
// conversation or contact models (attribute_model field).
//
// Chatwoot compatibility notes:
// - JSON uses "attribute_key" (Chatwoot name) as alias for attribute_name
// - JSON uses "attribute_display_type" (Chatwoot name) as alias for attribute_type
// - JSON uses "attribute_description" (Chatwoot name) as alias for description
// - attribute_values stores predefined options for list-type attributes
// - regex_pattern / regex_cue provide input validation beyond type checking
type CustomAttributeDefinition struct {
Base
AccountID uint `gorm:"index;not null" json:"account_id"`
AttributeName string `gorm:"size:255;not null;uniqueIndex:idx_attr_name_account_model" json:"attribute_key"` // Chatwoot: attribute_key
AttributeDisplayName string `gorm:"size:255;not null" json:"attribute_display_name"`
AttributeType string `gorm:"size:50;not null;default:text" json:"attribute_display_type"` // Chatwoot: attribute_display_type; text, number, date, checkbox, list, link
AttributeModel string `gorm:"size:50;not null;uniqueIndex:idx_attr_name_account_model" json:"attribute_model"` // conversation, contact
DefaultValue datatypes.JSON `gorm:"type:jsonb" json:"default_value,omitempty"`
AttributeValues datatypes.JSON `gorm:"type:jsonb" json:"attribute_values,omitempty"` // Chatwoot: predefined valid values for list-type attributes
RegexPattern string `gorm:"size:255" json:"regex_pattern,omitempty"` // Chatwoot: regex validation pattern
RegexCue string `gorm:"size:255" json:"regex_cue,omitempty"` // Chatwoot: human-readable hint about the regex constraint
Description string `gorm:"type:text" json:"attribute_description,omitempty"` // Chatwoot: attribute_description
}
func (CustomAttributeDefinition) TableName() string { return "custom_attribute_definitions" }