feat(models): rename ModelPublicUser to ModelPublicUsers and update references
Some checks failed
CI / Test (1.22) (push) Failing after -22m18s
CI / Test (1.23) (push) Failing after -22m7s
CI / Lint (push) Failing after -22m32s
CI / Build (push) Failing after -22m38s

* Update user-related models to use plural naming for consistency
* Add relationships to ModelPublicUsers in related models
* Adjust database migration and schema to reflect changes
* Remove deprecated ModelPublicUser
This commit is contained in:
Hein
2026-02-20 17:56:02 +02:00
parent a3ff2dc497
commit cecbd2cef5
13 changed files with 107 additions and 89 deletions

View File

@@ -21,6 +21,7 @@ type ModelPublicAPIKey struct {
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

View File

@@ -20,7 +20,8 @@ type ModelPublicEventLog struct {
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
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

View File

@@ -25,6 +25,7 @@ type ModelPublicHook struct {
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

View File

@@ -17,6 +17,7 @@ type ModelPublicSession struct {
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

View File

@@ -1,67 +0,0 @@
// Code generated by relspecgo. DO NOT EDIT.
package models
import (
"fmt"
resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes"
"github.com/uptrace/bun"
)
type ModelPublicUser struct {
bun.BaseModel `bun:"table:public.user,alias:user"`
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"`
}
// TableName returns the table name for ModelPublicUser
func (m ModelPublicUser) TableName() string {
return "public.user"
}
// TableNameOnly returns the table name without schema for ModelPublicUser
func (m ModelPublicUser) TableNameOnly() string {
return "user"
}
// SchemaName returns the schema name for ModelPublicUser
func (m ModelPublicUser) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicUser) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicUser) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicUser) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicUser) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicUser) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicUser) GetPrefix() string {
return "USE"
}

View File

@@ -0,0 +1,72 @@
// Code generated by relspecgo. DO NOT EDIT.
package models
import (
"fmt"
resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes"
"github.com/uptrace/bun"
)
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 []*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
}
// 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"
}
// SchemaName returns the schema name for ModelPublicUsers
func (m ModelPublicUsers) SchemaName() string {
return "public"
}
// GetID returns the primary key value
func (m ModelPublicUsers) GetID() int64 {
return m.ID.Int64()
}
// GetIDStr returns the primary key as a string
func (m ModelPublicUsers) GetIDStr() string {
return fmt.Sprintf("%d", m.ID)
}
// SetID sets the primary key value
func (m ModelPublicUsers) SetID(newid int64) {
m.UpdateID(newid)
}
// UpdateID updates the primary key value
func (m *ModelPublicUsers) UpdateID(newid int64) {
m.ID.FromString(fmt.Sprintf("%d", newid))
}
// GetIDName returns the name of the primary key column
func (m ModelPublicUsers) GetIDName() string {
return "id"
}
// GetPrefix returns the table prefix
func (m ModelPublicUsers) GetPrefix() string {
return "USE"
}

View File

@@ -22,6 +22,7 @@ type ModelPublicWhatsappAccount struct {
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