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.
54 lines
2.5 KiB
Go
54 lines
2.5 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
// Account represents a tenant/organization in the system.
|
|
type Account struct {
|
|
Base
|
|
Name string `gorm:"size:255;not null" json:"name"`
|
|
Domain string `gorm:"size:255" json:"domain,omitempty"`
|
|
Locale string `gorm:"size:10;default:en" json:"locale"`
|
|
Timezone string `gorm:"size:50;default:UTC" json:"timezone"`
|
|
ReportingTimezone string `gorm:"size:100" json:"reporting_timezone,omitempty"`
|
|
Active bool `gorm:"default:true" json:"active"`
|
|
Status string `gorm:"size:50;default:active" json:"status"`
|
|
OnboardingStep string `gorm:"size:100" json:"onboarding_step,omitempty"`
|
|
CustomAttributes datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"custom_attributes,omitempty"`
|
|
FeatureFlags string `gorm:"type:text" json:"feature_flags,omitempty"` // JSON-encoded feature flags
|
|
AutoResolveDuration int `gorm:"default:0" json:"auto_resolve_duration,omitempty"` // days
|
|
Limits datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"limits,omitempty"` // Chatwoot account limits, e.g. emails
|
|
AgentLimit int `gorm:"default:0" json:"agent_limit,omitempty"` // max agents allowed (0 = unlimited), Chatwoot usage_limits[:agents]
|
|
InboxLimit int `gorm:"default:0" json:"inbox_limit,omitempty"` // max inboxes allowed (0 = unlimited), Chatwoot usage_limits[:inboxes]
|
|
CaptainModels datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"captain_models,omitempty"`
|
|
CaptainFeatures datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"captain_features,omitempty"`
|
|
// Chatwoot: store_accessor :settings, :keep_pending_on_bot_failure
|
|
// When true, agent bot webhook failures do NOT reopen pending conversations.
|
|
KeepPendingOnBotFailure bool `gorm:"default:false" json:"keep_pending_on_bot_failure,omitempty"`
|
|
}
|
|
|
|
func (Account) TableName() string { return "accounts" }
|
|
|
|
func (a *Account) CustomAttributesMap() map[string]any {
|
|
attrs := map[string]any{}
|
|
if len(a.CustomAttributes) > 0 {
|
|
_ = json.Unmarshal(a.CustomAttributes, &attrs)
|
|
}
|
|
return attrs
|
|
}
|
|
|
|
func (a *Account) SetCustomAttributesMap(attrs map[string]any) error {
|
|
if attrs == nil {
|
|
attrs = map[string]any{}
|
|
}
|
|
encoded, err := json.Marshal(attrs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
a.CustomAttributes = datatypes.JSON(encoded)
|
|
return nil
|
|
}
|