fix(models): update models to use public schema and correct types
Some checks failed
CI / Test (1.22) (push) Failing after -23m2s
CI / Test (1.23) (push) Failing after -22m58s
CI / Lint (push) Has been cancelled
CI / Build (push) Has been cancelled

* Rename models to plural form for consistency
* Change table names to include 'public' schema
* Update timestamp types to SqlTimeStamp for consistency
* Adjust relationships to use pluralized user models
This commit is contained in:
Hein
2026-02-20 16:11:23 +02:00
parent 3fb65e0285
commit 524bc4179b
9 changed files with 233 additions and 199 deletions

View File

@@ -7,66 +7,65 @@ import (
"github.com/uptrace/bun"
)
type ModelPublicWhatsappAccount struct {
bun.BaseModel `bun:"table:whatsapp_accounts,alias:whatsapp_accounts"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
AccountID resolvespec_common.SqlString `bun:"account_id,type:varchar(100),unique,nullzero," json:"account_id"` // User-friendly unique identifier
AccountType resolvespec_common.SqlString `bun:"account_type,type:varchar(50),notnull," json:"account_type"` // whatsmeow or business-api
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
Config resolvespec_common.SqlString `bun:"config,type:text,nullzero," json:"config"` // JSON encoded additional config
CreatedAt resolvespec_common.SqlTime `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
DeletedAt resolvespec_common.SqlTime `bun:"deleted_at,type:timestamp,nullzero," json:"deleted_at"`
DisplayName resolvespec_common.SqlString `bun:"display_name,type:varchar(255),nullzero," json:"display_name"`
LastConnectedAt resolvespec_common.SqlTime `bun:"last_connected_at,type:timestamp,nullzero," json:"last_connected_at"`
PhoneNumber resolvespec_common.SqlString `bun:"phone_number,type:varchar(50),notnull," json:"phone_number"`
SessionPath resolvespec_common.SqlString `bun:"session_path,type:text,nullzero," json:"session_path"`
Status resolvespec_common.SqlString `bun:"status,type:varchar(50),default:disconnected,notnull," json:"status"` // connected
UpdatedAt resolvespec_common.SqlTime `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),notnull," json:"user_id"`
RelUserID *ModelPublicUser `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUser
type ModelPublicWhatsappAccounts struct {
bun.BaseModel `bun:"table:public.whatsapp_accounts,alias:whatsapp_accounts"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
AccountType resolvespec_common.SqlString `bun:"account_type,type:varchar(50),notnull," json:"account_type"` // whatsmeow or business-api
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
Config resolvespec_common.SqlString `bun:"config,type:text,nullzero," json:"config"` // JSON encoded additional config
CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
DeletedAt resolvespec_common.SqlTimeStamp `bun:"deleted_at,type:timestamp,nullzero," json:"deleted_at"`
DisplayName resolvespec_common.SqlString `bun:"display_name,type:varchar(255),nullzero," json:"display_name"`
LastConnectedAt resolvespec_common.SqlTimeStamp `bun:"last_connected_at,type:timestamp,nullzero," json:"last_connected_at"`
PhoneNumber resolvespec_common.SqlString `bun:"phone_number,type:varchar(50),notnull," json:"phone_number"`
SessionPath resolvespec_common.SqlString `bun:"session_path,type:text,nullzero," json:"session_path"`
Status resolvespec_common.SqlString `bun:"status,type:varchar(50),default:'disconnected',notnull," json:"status"` // connected
UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),notnull," json:"user_id"`
RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers
}
// TableName returns the table name for ModelPublicWhatsappAccount
func (m ModelPublicWhatsappAccount) TableName() string {
// TableName returns the table name for ModelPublicWhatsappAccounts
func (m ModelPublicWhatsappAccounts) TableName() string {
return "public.whatsapp_accounts"
}
// TableNameOnly returns the table name without schema for ModelPublicWhatsappAccounts
func (m ModelPublicWhatsappAccounts) TableNameOnly() string {
return "whatsapp_accounts"
}
// TableNameOnly returns the table name without schema for ModelPublicWhatsappAccount
func (m ModelPublicWhatsappAccount) TableNameOnly() string {
return "whatsapp_accounts"
}
// SchemaName returns the schema name for ModelPublicWhatsappAccount
func (m ModelPublicWhatsappAccount) SchemaName() string {
// SchemaName returns the schema name for ModelPublicWhatsappAccounts
func (m ModelPublicWhatsappAccounts) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicWhatsappAccount) GetID() int64 {
func (m ModelPublicWhatsappAccounts) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicWhatsappAccount) GetIDStr() string {
func (m ModelPublicWhatsappAccounts) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicWhatsappAccount) SetID(newid int64) {
func (m ModelPublicWhatsappAccounts) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicWhatsappAccount) UpdateID(newid int64) {
func (m *ModelPublicWhatsappAccounts) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicWhatsappAccount) GetIDName() string {
func (m ModelPublicWhatsappAccounts) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicWhatsappAccount) GetPrefix() string {
func (m ModelPublicWhatsappAccounts) GetPrefix() string {
return "WAH"
}