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