fix(models): update models to use public schema and correct types
* 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:
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user