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,64 +7,64 @@ import (
"github.com/uptrace/bun"
)
type ModelPublicAPIKey struct {
bun.BaseModel `bun:"table:api_keys,alias:api_keys"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
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"`
ExpiresAt resolvespec_common.SqlTime `bun:"expires_at,type:timestamp,nullzero," json:"expires_at"`
Key resolvespec_common.SqlString `bun:"key,type:varchar(255),notnull," json:"key"` // Hashed API key
KeyPrefix resolvespec_common.SqlString `bun:"key_prefix,type:varchar(20),nullzero," json:"key_prefix"` // First few characters for display
LastUsedAt resolvespec_common.SqlTime `bun:"last_used_at,type:timestamp,nullzero," json:"last_used_at"`
Name resolvespec_common.SqlString `bun:"name,type:varchar(255),notnull," json:"name"` // Friendly name for the API key
Permissions resolvespec_common.SqlString `bun:"permissions,type:text,nullzero," json:"permissions"` // JSON array of permissions
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 ModelPublicAPIKeys struct {
bun.BaseModel `bun:"table:public.api_keys,alias:api_keys"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
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"`
ExpiresAt resolvespec_common.SqlTimeStamp `bun:"expires_at,type:timestamp,nullzero," json:"expires_at"`
Key resolvespec_common.SqlString `bun:"key,type:varchar(255),notnull," json:"key"` // Hashed API key
KeyPrefix resolvespec_common.SqlString `bun:"key_prefix,type:varchar(20),nullzero," json:"key_prefix"` // First few characters for display
LastUsedAt resolvespec_common.SqlTimeStamp `bun:"last_used_at,type:timestamp,nullzero," json:"last_used_at"`
Name resolvespec_common.SqlString `bun:"name,type:varchar(255),notnull," json:"name"` // Friendly name for the API key
Permissions resolvespec_common.SqlString `bun:"permissions,type:text,nullzero," json:"permissions"` // JSON array of permissions
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 ModelPublicAPIKey
func (m ModelPublicAPIKey) TableName() string {
// TableName returns the table name for ModelPublicAPIKeys
func (m ModelPublicAPIKeys) TableName() string {
return "public.api_keys"
}
// TableNameOnly returns the table name without schema for ModelPublicAPIKeys
func (m ModelPublicAPIKeys) TableNameOnly() string {
return "api_keys"
}
// TableNameOnly returns the table name without schema for ModelPublicAPIKey
func (m ModelPublicAPIKey) TableNameOnly() string {
return "api_keys"
}
// SchemaName returns the schema name for ModelPublicAPIKey
func (m ModelPublicAPIKey) SchemaName() string {
// SchemaName returns the schema name for ModelPublicAPIKeys
func (m ModelPublicAPIKeys) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicAPIKey) GetID() int64 {
func (m ModelPublicAPIKeys) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicAPIKey) GetIDStr() string {
func (m ModelPublicAPIKeys) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicAPIKey) SetID(newid int64) {
func (m ModelPublicAPIKeys) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicAPIKey) UpdateID(newid int64) {
func (m *ModelPublicAPIKeys) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicAPIKey) GetIDName() string {
func (m ModelPublicAPIKeys) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicAPIKey) GetPrefix() string {
func (m ModelPublicAPIKeys) GetPrefix() string {
return "AKP"
}

View File

@@ -7,64 +7,64 @@ import (
"github.com/uptrace/bun"
)
type ModelPublicEventLog struct {
bun.BaseModel `bun:"table:event_logs,alias:event_logs"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Action resolvespec_common.SqlString `bun:"action,type:varchar(50),nullzero," json:"action"` // create
CreatedAt resolvespec_common.SqlTime `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
Data resolvespec_common.SqlString `bun:"data,type:text,nullzero," json:"data"` // JSON encoded event data
EntityID resolvespec_common.SqlString `bun:"entity_id,type:varchar(36),nullzero," json:"entity_id"`
EntityType resolvespec_common.SqlString `bun:"entity_type,type:varchar(100),nullzero," json:"entity_type"` // user
Error resolvespec_common.SqlString `bun:"error,type:text,nullzero," json:"error"`
EventType resolvespec_common.SqlString `bun:"event_type,type:varchar(100),notnull," json:"event_type"`
IpAddress resolvespec_common.SqlString `bun:"ip_address,type:varchar(50),nullzero," json:"ip_address"`
Success bool `bun:"success,type:boolean,default:true,notnull," json:"success"`
UserAgent resolvespec_common.SqlString `bun:"user_agent,type:text,nullzero," json:"user_agent"`
UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),nullzero," json:"user_id"` // Optional user reference
RelUserID *ModelPublicUser `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUser
type ModelPublicEventLogs struct {
bun.BaseModel `bun:"table:public.event_logs,alias:event_logs"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Action resolvespec_common.SqlString `bun:"action,type:varchar(50),nullzero," json:"action"` // create
CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
Data resolvespec_common.SqlString `bun:"data,type:text,nullzero," json:"data"` // JSON encoded event data
EntityID resolvespec_common.SqlString `bun:"entity_id,type:varchar(36),nullzero," json:"entity_id"`
EntityType resolvespec_common.SqlString `bun:"entity_type,type:varchar(100),nullzero," json:"entity_type"` // user
Error resolvespec_common.SqlString `bun:"error,type:text,nullzero," json:"error"`
EventType resolvespec_common.SqlString `bun:"event_type,type:varchar(100),notnull," json:"event_type"`
IpAddress resolvespec_common.SqlString `bun:"ip_address,type:varchar(50),nullzero," json:"ip_address"`
Success bool `bun:"success,type:boolean,default:true,notnull," json:"success"`
UserAgent resolvespec_common.SqlString `bun:"user_agent,type:text,nullzero," json:"user_agent"`
UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),nullzero," json:"user_id"` // Optional user reference
RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers
}
// TableName returns the table name for ModelPublicEventLog
func (m ModelPublicEventLog) TableName() string {
// TableName returns the table name for ModelPublicEventLogs
func (m ModelPublicEventLogs) TableName() string {
return "public.event_logs"
}
// TableNameOnly returns the table name without schema for ModelPublicEventLogs
func (m ModelPublicEventLogs) TableNameOnly() string {
return "event_logs"
}
// TableNameOnly returns the table name without schema for ModelPublicEventLog
func (m ModelPublicEventLog) TableNameOnly() string {
return "event_logs"
}
// SchemaName returns the schema name for ModelPublicEventLog
func (m ModelPublicEventLog) SchemaName() string {
// SchemaName returns the schema name for ModelPublicEventLogs
func (m ModelPublicEventLogs) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicEventLog) GetID() int64 {
func (m ModelPublicEventLogs) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicEventLog) GetIDStr() string {
func (m ModelPublicEventLogs) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicEventLog) SetID(newid int64) {
func (m ModelPublicEventLogs) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicEventLog) UpdateID(newid int64) {
func (m *ModelPublicEventLogs) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicEventLog) GetIDName() string {
func (m ModelPublicEventLogs) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicEventLog) GetPrefix() string {
func (m ModelPublicEventLogs) GetPrefix() string {
return "ELV"
}

View File

@@ -7,68 +7,68 @@ import (
"github.com/uptrace/bun"
)
type ModelPublicHook struct {
bun.BaseModel `bun:"table:hooks,alias:hooks"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
AllowInsecure bool `bun:"allow_insecure,type:boolean,default:false,notnull," json:"allow_insecure"` // Skip TLS certificate verification
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"`
Description resolvespec_common.SqlString `bun:"description,type:text,nullzero," json:"description"`
Events resolvespec_common.SqlString `bun:"events,type:text,nullzero," json:"events"` // JSON array of event types
Headers resolvespec_common.SqlString `bun:"headers,type:text,nullzero," json:"headers"` // JSON encoded headers
Method resolvespec_common.SqlString `bun:"method,type:varchar(10),default:POST,notnull," json:"method"` // HTTP method
Name resolvespec_common.SqlString `bun:"name,type:varchar(255),notnull," json:"name"`
RetryCount resolvespec_common.SqlInt32 `bun:"retry_count,type:int,default:3,notnull," json:"retry_count"`
Secret resolvespec_common.SqlString `bun:"secret,type:varchar(255),nullzero," json:"secret"` // HMAC signature secret
Timeout resolvespec_common.SqlInt32 `bun:"timeout,type:int,default:30,notnull," json:"timeout"` // Timeout in seconds
UpdatedAt resolvespec_common.SqlTime `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
URL resolvespec_common.SqlString `bun:"url,type:text,notnull," json:"url"`
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 ModelPublicHooks struct {
bun.BaseModel `bun:"table:public.hooks,alias:hooks"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
AllowInsecure bool `bun:"allow_insecure,type:boolean,default:false,notnull," json:"allow_insecure"` // Skip TLS certificate verification
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"`
Description resolvespec_common.SqlString `bun:"description,type:text,nullzero," json:"description"`
Events resolvespec_common.SqlString `bun:"events,type:text,nullzero," json:"events"` // JSON array of event types
Headers resolvespec_common.SqlString `bun:"headers,type:text,nullzero," json:"headers"` // JSON encoded headers
Method resolvespec_common.SqlString `bun:"method,type:varchar(10),default:'POST',notnull," json:"method"` // HTTP method
Name resolvespec_common.SqlString `bun:"name,type:varchar(255),notnull," json:"name"`
RetryCount resolvespec_common.SqlInt32 `bun:"retry_count,type:int,default:3,notnull," json:"retry_count"`
Secret resolvespec_common.SqlString `bun:"secret,type:varchar(255),nullzero," json:"secret"` // HMAC signature secret
Timeout resolvespec_common.SqlInt32 `bun:"timeout,type:int,default:30,notnull," json:"timeout"` // Timeout in seconds
UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
URL resolvespec_common.SqlString `bun:"url,type:text,notnull," json:"url"`
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 ModelPublicHook
func (m ModelPublicHook) TableName() string {
// TableName returns the table name for ModelPublicHooks
func (m ModelPublicHooks) TableName() string {
return "public.hooks"
}
// TableNameOnly returns the table name without schema for ModelPublicHooks
func (m ModelPublicHooks) TableNameOnly() string {
return "hooks"
}
// TableNameOnly returns the table name without schema for ModelPublicHook
func (m ModelPublicHook) TableNameOnly() string {
return "hooks"
}
// SchemaName returns the schema name for ModelPublicHook
func (m ModelPublicHook) SchemaName() string {
// SchemaName returns the schema name for ModelPublicHooks
func (m ModelPublicHooks) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicHook) GetID() int64 {
func (m ModelPublicHooks) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicHook) GetIDStr() string {
func (m ModelPublicHooks) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicHook) SetID(newid int64) {
func (m ModelPublicHooks) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicHook) UpdateID(newid int64) {
func (m *ModelPublicHooks) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicHook) GetIDName() string {
func (m ModelPublicHooks) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicHook) GetPrefix() string {
func (m ModelPublicHooks) GetPrefix() string {
return "HOO"
}

View File

@@ -8,21 +8,21 @@ import (
)
type ModelPublicMessageCache struct {
bun.BaseModel `bun:"table:message_cache,alias:message_cache"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
AccountID resolvespec_common.SqlString `bun:"account_id,type:varchar(36),notnull," json:"account_id"`
ChatID resolvespec_common.SqlString `bun:"chat_id,type:varchar(255),notnull," json:"chat_id"`
Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` // JSON encoded message content
CreatedAt resolvespec_common.SqlTime `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
FromMe bool `bun:"from_me,type:boolean,notnull," json:"from_me"`
MessageID resolvespec_common.SqlString `bun:"message_id,type:varchar(255),notnull," json:"message_id"`
MessageType resolvespec_common.SqlString `bun:"message_type,type:varchar(50),notnull," json:"message_type"` // text
Timestamp resolvespec_common.SqlTime `bun:"timestamp,type:timestamp,notnull," json:"timestamp"`
bun.BaseModel `bun:"table:public.message_cache,alias:message_cache"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
AccountID resolvespec_common.SqlString `bun:"account_id,type:varchar(36),notnull," json:"account_id"`
ChatID resolvespec_common.SqlString `bun:"chat_id,type:varchar(255),notnull," json:"chat_id"`
Content resolvespec_common.SqlString `bun:"content,type:text,notnull," json:"content"` // JSON encoded message content
CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
FromMe bool `bun:"from_me,type:boolean,notnull," json:"from_me"`
MessageID resolvespec_common.SqlString `bun:"message_id,type:varchar(255),notnull," json:"message_id"`
MessageType resolvespec_common.SqlString `bun:"message_type,type:varchar(50),notnull," json:"message_type"` // text
Timestamp resolvespec_common.SqlTimeStamp `bun:"timestamp,type:timestamp,notnull," json:"timestamp"`
}
// TableName returns the table name for ModelPublicMessageCache
func (m ModelPublicMessageCache) TableName() string {
return "message_cache"
return "public.message_cache"
}
// TableNameOnly returns the table name without schema for ModelPublicMessageCache

View File

@@ -7,60 +7,60 @@ import (
"github.com/uptrace/bun"
)
type ModelPublicSession struct {
bun.BaseModel `bun:"table:sessions,alias:sessions"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
CreatedAt resolvespec_common.SqlTime `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
ExpiresAt resolvespec_common.SqlTime `bun:"expires_at,type:timestamp,notnull," json:"expires_at"`
IpAddress resolvespec_common.SqlString `bun:"ip_address,type:varchar(50),nullzero," json:"ip_address"`
Token resolvespec_common.SqlString `bun:"token,type:varchar(255),notnull," json:"token"` // Session token hash
UpdatedAt resolvespec_common.SqlTime `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
UserAgent resolvespec_common.SqlString `bun:"user_agent,type:text,nullzero," json:"user_agent"`
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 ModelPublicSessions struct {
bun.BaseModel `bun:"table:public.sessions,alias:sessions"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"`
ExpiresAt resolvespec_common.SqlTimeStamp `bun:"expires_at,type:timestamp,notnull," json:"expires_at"`
IpAddress resolvespec_common.SqlString `bun:"ip_address,type:varchar(50),nullzero," json:"ip_address"`
Token resolvespec_common.SqlString `bun:"token,type:varchar(255),notnull," json:"token"` // Session token hash
UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
UserAgent resolvespec_common.SqlString `bun:"user_agent,type:text,nullzero," json:"user_agent"`
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 ModelPublicSession
func (m ModelPublicSession) TableName() string {
// TableName returns the table name for ModelPublicSessions
func (m ModelPublicSessions) TableName() string {
return "public.sessions"
}
// TableNameOnly returns the table name without schema for ModelPublicSessions
func (m ModelPublicSessions) TableNameOnly() string {
return "sessions"
}
// TableNameOnly returns the table name without schema for ModelPublicSession
func (m ModelPublicSession) TableNameOnly() string {
return "sessions"
}
// SchemaName returns the schema name for ModelPublicSession
func (m ModelPublicSession) SchemaName() string {
// SchemaName returns the schema name for ModelPublicSessions
func (m ModelPublicSessions) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicSession) GetID() int64 {
func (m ModelPublicSessions) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicSession) GetIDStr() string {
func (m ModelPublicSessions) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicSession) SetID(newid int64) {
func (m ModelPublicSessions) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicSession) UpdateID(newid int64) {
func (m *ModelPublicSessions) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicSession) GetIDName() string {
func (m ModelPublicSessions) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicSession) GetPrefix() string {
func (m ModelPublicSessions) GetPrefix() string {
return "SES"
}

View File

@@ -7,66 +7,66 @@ import (
"github.com/uptrace/bun"
)
type ModelPublicUser struct {
bun.BaseModel `bun:"table:users,alias:users"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
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"` // Soft delete
Email resolvespec_common.SqlString `bun:"email,type:varchar(255),notnull," json:"email"`
FullName resolvespec_common.SqlString `bun:"full_name,type:varchar(255),nullzero," json:"full_name"`
Password resolvespec_common.SqlString `bun:"password,type:varchar(255),notnull," json:"password"` // Bcrypt hashed password
Role resolvespec_common.SqlString `bun:"role,type:varchar(50),default:user,notnull," json:"role"` // admin
UpdatedAt resolvespec_common.SqlTime `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
Username resolvespec_common.SqlString `bun:"username,type:varchar(255),notnull," json:"username"`
RelUserIDPublicAPIKeys []*ModelPublicAPIKey `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicapikeys,omitempty"` // Has many ModelPublicAPIKey
RelUserIDPublicHooks []*ModelPublicHook `bun:"rel:has-many,join:id=user_id" json:"reluseridpublichooks,omitempty"` // Has many ModelPublicHook
RelUserIDPublicWhatsappAccounts []*ModelPublicWhatsappAccount `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicwhatsappaccounts,omitempty"` // Has many ModelPublicWhatsappAccount
RelUserIDPublicEventLogs []*ModelPublicEventLog `bun:"rel:has-many,join:id=user_id" json:"reluseridpubliceventlogs,omitempty"` // Has many ModelPublicEventLog
RelUserIDPublicSessions []*ModelPublicSession `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicsessions,omitempty"` // Has many ModelPublicSession
type ModelPublicUsers struct {
bun.BaseModel `bun:"table:public.users,alias:users"`
ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID
Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"`
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"` // Soft delete
Email resolvespec_common.SqlString `bun:"email,type:varchar(255),notnull," json:"email"`
FullName resolvespec_common.SqlString `bun:"full_name,type:varchar(255),nullzero," json:"full_name"`
Password resolvespec_common.SqlString `bun:"password,type:varchar(255),notnull," json:"password"` // Bcrypt hashed password
Role resolvespec_common.SqlString `bun:"role,type:varchar(50),default:'user',notnull," json:"role"` // admin
UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"`
Username resolvespec_common.SqlString `bun:"username,type:varchar(255),notnull," json:"username"`
RelUserIDPublicAPIKeys []*ModelPublicAPIKeys `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicapikeys,omitempty"` // Has many ModelPublicAPIKeys
RelUserIDPublicHooks []*ModelPublicHooks `bun:"rel:has-many,join:id=user_id" json:"reluseridpublichooks,omitempty"` // Has many ModelPublicHooks
RelUserIDPublicWhatsappAccounts []*ModelPublicWhatsappAccounts `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicwhatsappaccounts,omitempty"` // Has many ModelPublicWhatsappAccounts
RelUserIDPublicEventLogs []*ModelPublicEventLogs `bun:"rel:has-many,join:id=user_id" json:"reluseridpubliceventlogs,omitempty"` // Has many ModelPublicEventLogs
RelUserIDPublicSessions []*ModelPublicSessions `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicsessions,omitempty"` // Has many ModelPublicSessions
}
// TableName returns the table name for ModelPublicUser
func (m ModelPublicUser) TableName() string {
// TableName returns the table name for ModelPublicUsers
func (m ModelPublicUsers) TableName() string {
return "public.users"
}
// TableNameOnly returns the table name without schema for ModelPublicUsers
func (m ModelPublicUsers) TableNameOnly() string {
return "users"
}
// TableNameOnly returns the table name without schema for ModelPublicUser
func (m ModelPublicUser) TableNameOnly() string {
return "users"
}
// SchemaName returns the schema name for ModelPublicUser
func (m ModelPublicUser) SchemaName() string {
// SchemaName returns the schema name for ModelPublicUsers
func (m ModelPublicUsers) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicUser) GetID() int64 {
func (m ModelPublicUsers) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicUser) GetIDStr() string {
func (m ModelPublicUsers) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicUser) SetID(newid int64) {
func (m ModelPublicUsers) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicUser) UpdateID(newid int64) {
func (m *ModelPublicUsers) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicUser) GetIDName() string {
func (m ModelPublicUsers) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicUser) GetPrefix() string {
func (m ModelPublicUsers) GetPrefix() string {
return "USE"
}

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"
}