models

package
v0.0.0-...-a78c924 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID() string

GenerateID creates a new nanoid suitable for use as a primary key or deploy path key.

func GetSetting

func GetSetting(db *gorm.DB, key string) (string, error)

func InitDB

func InitDB(cfg config.DBConfig) (*gorm.DB, error)

func SeedDefaults

func SeedDefaults(db *gorm.DB, cfg *config.Config) error

func SetSetting

func SetSetting(db *gorm.DB, key, value string) error

Types

type APIKey

type APIKey struct {
	ID         string     `gorm:"primaryKey;size:20" json:"id"`
	UserID     string     `gorm:"index;not null" json:"user_id"`
	KeyHash    string     `gorm:"uniqueIndex;not null" json:"-"`
	Name       string     `gorm:"not null" json:"name"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`

	User User `gorm:"foreignKey:UserID" json:"-"`
}

func (*APIKey) BeforeCreate

func (k *APIKey) BeforeCreate(_ *gorm.DB) error

type AuditLog

type AuditLog struct {
	ID           int64     `gorm:"primaryKey;autoIncrement" json:"id"`
	ActorID      string    `gorm:"index;size:20;not null" json:"actor_id"`
	ActorEmail   string    `gorm:"size:255;not null" json:"actor_email"`
	Action       string    `gorm:"index;size:50;not null" json:"action"`
	ResourceType string    `gorm:"index:idx_audit_resource;size:30;not null" json:"resource_type"`
	ResourceID   string    `gorm:"index:idx_audit_resource;size:20" json:"resource_id"`
	IPAddress    string    `gorm:"size:45" json:"ip_address"`
	Details      *string   `gorm:"type:text" json:"details,omitempty"`
	CreatedAt    time.Time `gorm:"index" json:"created_at"`
}

AuditLog records user actions for accountability and incident investigation.

type AuthCode

type AuthCode struct {
	ID            string    `gorm:"primaryKey;size:20" json:"id"`
	Code          string    `gorm:"uniqueIndex;not null" json:"-"`
	UserID        string    `gorm:"not null" json:"user_id"`
	CodeChallenge string    `gorm:"not null" json:"-"`
	Used          bool      `gorm:"default:false" json:"-"`
	ExpiresAt     time.Time `gorm:"not null" json:"-"`
	CreatedAt     time.Time `json:"created_at"`
}

func (*AuthCode) BeforeCreate

func (a *AuthCode) BeforeCreate(_ *gorm.DB) error

type CacheEntry

type CacheEntry struct {
	ID        uint   `gorm:"primaryKey"`
	SiteID    string `gorm:"index:idx_cache_lookup"`
	CacheName string `gorm:"index:idx_cache_lookup"`
	URL       string `gorm:"index:idx_cache_lookup"`
	Status    int
	Headers   string
	Body      []byte
	ExpiresAt *time.Time
	CreatedAt time.Time
}

CacheEntry stores a cached HTTP response for the Cache API.

type CronSchedule

type CronSchedule struct {
	ID        string     `gorm:"primaryKey;size:20" json:"id"`
	SiteID    string     `gorm:"index;not null" json:"site_id"`
	Cron      string     `gorm:"not null" json:"cron"`
	Enabled   bool       `gorm:"default:true" json:"enabled"`
	LastRunAt *time.Time `json:"last_run_at,omitempty"`
	CreatedAt time.Time  `json:"created_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

func (*CronSchedule) BeforeCreate

func (cs *CronSchedule) BeforeCreate(_ *gorm.DB) error

type D1Database

type D1Database struct {
	ID         string    `gorm:"primaryKey;size:20" json:"id"`
	SiteID     string    `gorm:"not null;uniqueIndex:idx_d1_databases_site_name,priority:1" json:"site_id"`
	Name       string    `gorm:"not null;uniqueIndex:idx_d1_databases_site_name,priority:2" json:"name"`
	DatabaseID string    `gorm:"uniqueIndex;not null" json:"database_id"`
	CreatedAt  time.Time `json:"created_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

D1Database represents a D1 database binding for a site.

func (*D1Database) BeforeCreate

func (d *D1Database) BeforeCreate(_ *gorm.DB) error

type Deployment

type Deployment struct {
	ID         string    `gorm:"primaryKey;size:20" json:"id"`
	SiteID     string    `gorm:"not null;uniqueIndex:idx_deployments_site_version,priority:1" json:"site_id"`
	Version    int       `gorm:"not null;uniqueIndex:idx_deployments_site_version,priority:2" json:"version"`
	FileHash   string    `gorm:"not null" json:"file_hash"`
	HasWorker  bool      `gorm:"default:false" json:"has_worker"`
	UploadedAt time.Time `json:"uploaded_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

func (*Deployment) BeforeCreate

func (d *Deployment) BeforeCreate(_ *gorm.DB) error

type DurableObjectEntry

type DurableObjectEntry struct {
	ID        uint   `gorm:"primaryKey"`
	Namespace string `gorm:"uniqueIndex:idx_do_lookup"`
	ObjectID  string `gorm:"uniqueIndex:idx_do_lookup"`
	Key       string `gorm:"uniqueIndex:idx_do_lookup"`
	ValueJSON string
}

DurableObjectEntry is the GORM model for durable object storage.

type DurableObjectNamespace

type DurableObjectNamespace struct {
	ID          string    `gorm:"primaryKey;size:20" json:"id"`
	SiteID      string    `gorm:"not null;uniqueIndex:idx_do_namespaces_site_name,priority:1" json:"site_id"`
	Name        string    `gorm:"not null;uniqueIndex:idx_do_namespaces_site_name,priority:2" json:"name"`
	NamespaceID string    `gorm:"uniqueIndex;not null" json:"namespace_id"`
	CreatedAt   time.Time `json:"created_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

DurableObjectNamespace represents a Durable Object namespace binding for a site.

func (*DurableObjectNamespace) BeforeCreate

func (d *DurableObjectNamespace) BeforeCreate(_ *gorm.DB) error

type Invite

type Invite struct {
	ID        string     `gorm:"primaryKey;size:20" json:"id"`
	Code      string     `gorm:"uniqueIndex;not null" json:"code"`
	CreatedBy string     `gorm:"not null" json:"created_by"`
	MaxUses   *int       `json:"max_uses,omitempty"`
	UseCount  int        `gorm:"default:0" json:"use_count"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	Active    bool       `gorm:"default:true" json:"active"`
	CreatedAt time.Time  `json:"created_at"`

	Creator User `gorm:"foreignKey:CreatedBy" json:"-"`
}

func (*Invite) BeforeCreate

func (i *Invite) BeforeCreate(_ *gorm.DB) error

type KVEntry

type KVEntry struct {
	ID          string     `gorm:"primaryKey;size:20" json:"id"`
	NamespaceID string     `gorm:"index;not null" json:"namespace_id"`
	Key         string     `gorm:"not null" json:"key"`
	Value       string     `gorm:"type:text" json:"value"`
	Metadata    *string    `gorm:"type:text" json:"metadata,omitempty"`
	ExpiresAt   *time.Time `json:"expires_at,omitempty"`

	Namespace KVNamespace `gorm:"foreignKey:NamespaceID" json:"-"`
}

func (*KVEntry) BeforeCreate

func (k *KVEntry) BeforeCreate(_ *gorm.DB) error

type KVNamespace

type KVNamespace struct {
	ID        string    `gorm:"primaryKey;size:20" json:"id"`
	SiteID    string    `gorm:"index;not null" json:"site_id"`
	Name      string    `gorm:"not null" json:"name"`
	CreatedAt time.Time `json:"created_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

func (*KVNamespace) BeforeCreate

func (k *KVNamespace) BeforeCreate(_ *gorm.DB) error

type RevokedToken

type RevokedToken struct {
	TokenHash string    `gorm:"primaryKey;size:64"` // SHA-256 of the raw JWT
	ExpiresAt time.Time `gorm:"index;not null"`     // When the JWT would naturally expire
}

RevokedToken tracks JWTs that have been explicitly revoked (e.g. logout). Entries are cleaned up after they expire.

type S3Credential

type S3Credential struct {
	ID            string     `gorm:"primaryKey;size:20" json:"id"`
	UserID        string     `gorm:"index;not null" json:"user_id"`
	ExternalKeyID string     `gorm:"uniqueIndex;not null" json:"external_key_id"`
	AccessKeyID   string     `gorm:"uniqueIndex;not null" json:"access_key_id"`
	Name          string     `gorm:"not null" json:"name"`
	LastUsedAt    *time.Time `json:"last_used_at,omitempty"`
	CreatedAt     time.Time  `json:"created_at"`

	User User `gorm:"foreignKey:UserID" json:"-"`
}

func (*S3Credential) BeforeCreate

func (sc *S3Credential) BeforeCreate(_ *gorm.DB) error

type Setting

type Setting struct {
	Key   string `gorm:"primaryKey" json:"key"`
	Value string `gorm:"not null" json:"value"`
}

type Site

type Site struct {
	ID             string    `gorm:"primaryKey;size:20" json:"id"`
	UserID         string    `gorm:"index;not null" json:"user_id"`
	SubdomainSlug  string    `gorm:"uniqueIndex;not null" json:"subdomain_slug"`
	Name           string    `gorm:"not null" json:"name"`
	SPAMode        bool      `gorm:"default:false" json:"spa_mode"`
	HasWorker      bool      `gorm:"default:false" json:"has_worker"`
	ActiveVersion  *int      `json:"active_version"`
	ActiveDeployID *string   `gorm:"size:20" json:"active_deploy_id,omitempty"`
	CreatedAt      time.Time `json:"created_at"`

	User        User         `gorm:"foreignKey:UserID" json:"-"`
	Deployments []Deployment `gorm:"foreignKey:SiteID" json:"deployments,omitempty"`
}

func (*Site) BeforeCreate

func (s *Site) BeforeCreate(_ *gorm.DB) error

type StorageBucket

type StorageBucket struct {
	ID         string    `gorm:"primaryKey;size:20" json:"id"`
	SiteID     string    `gorm:"not null;uniqueIndex:idx_storage_buckets_site_name,priority:1" json:"site_id"`
	Name       string    `gorm:"not null;uniqueIndex:idx_storage_buckets_site_name,priority:2" json:"name"`
	BucketName string    `gorm:"uniqueIndex;not null" json:"bucket_name"`
	Public     bool      `gorm:"default:false" json:"public"`
	CreatedAt  time.Time `json:"created_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

func (*StorageBucket) BeforeCreate

func (sb *StorageBucket) BeforeCreate(_ *gorm.DB) error

type User

type User struct {
	ID           string    `gorm:"primaryKey;size:20" json:"id"`
	Email        string    `gorm:"uniqueIndex;not null" json:"email"`
	PasswordHash string    `gorm:"not null" json:"-"`
	Role         string    `gorm:"not null;default:user" json:"role"` // superadmin | admin | user
	InvitedBy    *string   `gorm:"size:20" json:"invited_by,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(_ *gorm.DB) error

type WorkerEnvVar

type WorkerEnvVar struct {
	ID     string `gorm:"primaryKey;size:20" json:"id"`
	SiteID string `gorm:"index;not null" json:"site_id"`
	Name   string `gorm:"not null" json:"name"`
	Value  string `gorm:"not null" json:"value"`
	Secret bool   `gorm:"default:false" json:"secret"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

func (*WorkerEnvVar) BeforeCreate

func (w *WorkerEnvVar) BeforeCreate(_ *gorm.DB) error

type WorkerLog

type WorkerLog struct {
	ID        string    `gorm:"primaryKey;size:20" json:"id"`
	SiteID    string    `gorm:"index;not null" json:"site_id"`
	Level     string    `gorm:"not null" json:"level"`
	Message   string    `gorm:"type:text;not null" json:"message"`
	CreatedAt time.Time `gorm:"index" json:"created_at"`

	Site Site `gorm:"foreignKey:SiteID" json:"-"`
}

func (*WorkerLog) BeforeCreate

func (wl *WorkerLog) BeforeCreate(_ *gorm.DB) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL