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,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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user