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