models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is the global database connection used by all model queries.

View Source
var MonitorDB *gorm.DB

MonitorDB is a separate database connection for monitor_stats.db.

Functions

func Checkpoint

func Checkpoint()

Checkpoint truncates the WAL file to prevent unbounded growth during long-running bulk operations. Call after bulk commands complete.

func CountSnapshotsByEnvironmentID

func CountSnapshotsByEnvironmentID(envID uint) (int64, error)

CountSnapshotsByEnvironmentID returns the number of snapshots for an environment.

func DeleteAccountByID

func DeleteAccountByID(accountID uint) error

DeleteAccountByID removes an account and its related junction table records.

func DeleteAccountSiteByID

func DeleteAccountSiteByID(id uint) error

DeleteAccountSiteByID removes an account_site junction row by its primary key.

func DeleteDomainByID

func DeleteDomainByID(id uint) error

DeleteDomainByID removes a domain record by its ID.

func DeleteEnvironmentByID

func DeleteEnvironmentByID(envID uint) error

DeleteEnvironmentByID removes an environment record by its ID.

func DeleteProviderByID

func DeleteProviderByID(id uint) error

DeleteProviderByID removes a provider record by its ID.

func DeleteSiteByID

func DeleteSiteByID(siteID uint) error

DeleteSiteByID removes a site and its related environments and account_site records.

func GetConfiguration

func GetConfiguration(captainID uint, key string) (string, error)

GetConfiguration retrieves a configuration value by captain ID and key.

func GetSystemLoad

func GetSystemLoad() float64

GetSystemLoad returns the 1-minute system load average.

func InitDB

func InitDB() error

InitDB opens (or creates) the SQLite database at data/captaincore.db under the user's ~/.captaincore directory and runs AutoMigrate for every model.

func InitMonitorDB

func InitMonitorDB() error

InitMonitorDB opens (or creates) the SQLite database at data/monitor_stats.db and runs AutoMigrate for the MonitorRun model.

func InsertSnapshot

func InsertSnapshot(snapshot *Snapshot) error

InsertSnapshot inserts a new snapshot record and populates the auto-incremented SnapshotID.

func LogMonitorRunEnd

func LogMonitorRunEnd(runID uint, siteCount, errorCount, retryAttempts, restoredCount int, notificationSent bool)

LogMonitorRunEnd updates a run record with end time, duration, site count, and completed status.

func LogMonitorRunSkipped

func LogMonitorRunSkipped(parallelism int)

LogMonitorRunSkipped inserts a run record with status "skipped_locked".

func LogMonitorRunStart

func LogMonitorRunStart(command string, parallelism int) uint

LogMonitorRunStart inserts a new run record with status "running" and returns its ID.

func ParseTargetString

func ParseTargetString(target string) (environment string, minorTargets []string)

ParseTargetString parses a target string like "@production.monitor-on" into environment and minor target components.

func SetConfiguration

func SetConfiguration(captainID uint, key, value string) error

SetConfiguration upserts a configuration value.

func UpsertAccount

func UpsertAccount(account Account) error

UpsertAccount inserts or updates an account record by account_id.

func UpsertAccountDomain

func UpsertAccountDomain(ad AccountDomain) error

UpsertAccountDomain inserts or updates an account_domain record by account_domain_id.

func UpsertAccountSite

func UpsertAccountSite(as AccountSite) error

UpsertAccountSite inserts or updates an account_site record by account_site_id.

func UpsertAccountUser

func UpsertAccountUser(au AccountUser) error

UpsertAccountUser inserts or updates an account_user record by account_user_id.

func UpsertConnection

func UpsertConnection(conn Connection) error

UpsertConnection inserts or updates a connection record by domain.

func UpsertDomain

func UpsertDomain(d Domain) error

UpsertDomain inserts or updates a domain record by domain_id.

func UpsertEnvironment

func UpsertEnvironment(env Environment, skipUsers bool) error

UpsertEnvironment inserts or updates an environment record by environment_id.

func UpsertProvider

func UpsertProvider(p Provider) error

UpsertProvider inserts or updates a provider record by provider_id.

func UpsertRecipe

func UpsertRecipe(recipe *Recipe) error

UpsertRecipe inserts or updates a recipe by recipe_id.

func UpsertSite

func UpsertSite(site Site) error

UpsertSite inserts or updates a site record by site_id.

Types

type Account

type Account struct {
	AccountID     uint   `gorm:"primaryKey;column:account_id;autoIncrement" json:"account_id,string"`
	BillingUserID uint   `gorm:"column:billing_user_id" json:"billing_user_id,string"`
	Name          string `gorm:"column:name" json:"name"`
	Defaults      string `gorm:"column:defaults;type:text" json:"defaults"`
	Plan          string `gorm:"column:plan;type:text" json:"plan"`
	Metrics       string `gorm:"column:metrics" json:"metrics"`
	Status        string `gorm:"column:status" json:"status"`
	CreatedAt     string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt     string `gorm:"column:updated_at" json:"updated_at"`
}

Account mirrors captaincore_accounts from the PHP schema.

func GetAccountByID

func GetAccountByID(id uint) (*Account, error)

GetAccountByID returns an account by its ID.

func (Account) TableName

func (Account) TableName() string

type AccountDomain

type AccountDomain struct {
	AccountDomainID uint   `gorm:"primaryKey;column:account_domain_id;autoIncrement" json:"account_domain_id,string"`
	AccountID       uint   `gorm:"column:account_id" json:"account_id,string"`
	DomainID        uint   `gorm:"column:domain_id" json:"domain_id,string"`
	CreatedAt       string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt       string `gorm:"column:updated_at" json:"updated_at"`
}

AccountDomain mirrors captaincore_account_domain junction table.

func (AccountDomain) TableName

func (AccountDomain) TableName() string

type AccountSite

type AccountSite struct {
	AccountSiteID uint   `gorm:"primaryKey;column:account_site_id;autoIncrement" json:"account_site_id,string"`
	AccountID     uint   `gorm:"column:account_id" json:"account_id,string"`
	SiteID        uint   `gorm:"column:site_id" json:"site_id,string"`
	CreatedAt     string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt     string `gorm:"column:updated_at" json:"updated_at"`
}

AccountSite mirrors captaincore_account_site junction table.

func (AccountSite) TableName

func (AccountSite) TableName() string

type AccountUser

type AccountUser struct {
	AccountUserID uint   `gorm:"primaryKey;column:account_user_id;autoIncrement" json:"account_user_id,string"`
	AccountID     uint   `gorm:"column:account_id" json:"account_id,string"`
	UserID        uint   `gorm:"column:user_id" json:"user_id,string"`
	Level         string `gorm:"column:level" json:"level"`
	CreatedAt     string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt     string `gorm:"column:updated_at" json:"updated_at"`
}

AccountUser mirrors captaincore_account_user junction table.

func (AccountUser) TableName

func (AccountUser) TableName() string

type AuthDetails

type AuthDetails struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type BackupSettings

type BackupSettings struct {
	Mode     string `json:"mode"`
	Interval string `json:"interval"`
	Active   bool   `json:"active"`
}

type Capture

type Capture struct {
	CaptureID     uint   `gorm:"primaryKey;column:capture_id;autoIncrement" json:"capture_id"`
	SiteID        uint   `gorm:"column:site_id" json:"site_id"`
	EnvironmentID uint   `gorm:"column:environment_id" json:"environment_id"`
	CreatedAt     string `gorm:"column:created_at" json:"created_at"`
	GitCommit     string `gorm:"column:git_commit" json:"git_commit"`
	Pages         string `gorm:"column:pages;type:text" json:"pages"`
}

Capture mirrors captaincore_captures from the PHP schema.

func (Capture) TableName

func (Capture) TableName() string

type Configuration

type Configuration struct {
	ConfigurationID uint   `gorm:"primaryKey;column:configuration_id;autoIncrement" json:"configuration_id"`
	CaptainID       uint   `gorm:"column:captain_id" json:"captain_id"`
	ConfigKey       string `gorm:"column:config_key" json:"config_key"`
	ConfigValue     string `gorm:"column:config_value;type:text" json:"config_value"`
	CreatedAt       string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt       string `gorm:"column:updated_at" json:"updated_at"`
}

Configuration is a generic key-value store for CaptainCore settings.

func (Configuration) TableName

func (Configuration) TableName() string

type Connection

type Connection struct {
	ID        uint   `gorm:"primaryKey;autoIncrement" json:"id"`
	CreatedAt string `gorm:"column:created_at" json:"created_at"`
	Domain    string `gorm:"column:domain;uniqueIndex" json:"domain"`
	Token     string `gorm:"column:token" json:"token"`
}

Connection stores CaptainCore connection records (migrated from WordPress options).

func GetAllConnections

func GetAllConnections() ([]Connection, error)

GetAllConnections returns all connections ordered by created_at descending.

func GetConnectionByDomain

func GetConnectionByDomain(domain string) (*Connection, error)

GetConnectionByDomain returns a connection matching the given domain.

func (Connection) TableName

func (Connection) TableName() string

type Domain

type Domain struct {
	DomainID         uint   `gorm:"primaryKey;column:domain_id;autoIncrement" json:"domain_id,string"`
	RemoteID         string `gorm:"column:remote_id" json:"remote_id"`
	ProviderID       string `gorm:"column:provider_id" json:"provider_id"`
	ProviderDomainID string `gorm:"column:provider_domain_id" json:"provider_domain_id"`
	Status           string `gorm:"column:status" json:"status"`
	Price            string `gorm:"column:price" json:"price"`
	Name             string `gorm:"column:name" json:"name"`
	Details          string `gorm:"column:details;type:text" json:"details"`
	CreatedAt        string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt        string `gorm:"column:updated_at" json:"updated_at"`
}

Domain mirrors captaincore_domains from the PHP schema.

func (Domain) TableName

func (Domain) TableName() string

type Environment

type Environment struct {
	EnvironmentID         uint   `gorm:"primaryKey;column:environment_id;autoIncrement" json:"environment_id,string"`
	SiteID                uint   `gorm:"column:site_id" json:"site_id,string"`
	CreatedAt             string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt             string `gorm:"column:updated_at" json:"updated_at"`
	Environment           string `gorm:"column:environment" json:"environment"`
	Address               string `gorm:"column:address" json:"address"`
	Username              string `gorm:"column:username" json:"username"`
	Password              string `gorm:"column:password" json:"password"`
	Protocol              string `gorm:"column:protocol" json:"protocol"`
	Port                  string `gorm:"column:port" json:"port"`
	Fathom                string `gorm:"column:fathom;type:text" json:"fathom"`
	HomeDirectory         string `gorm:"column:home_directory" json:"home_directory"`
	DatabaseName          string `gorm:"column:database_name" json:"database_name"`
	DatabaseUsername      string `gorm:"column:database_username" json:"database_username"`
	DatabasePassword      string `gorm:"column:database_password" json:"database_password"`
	OffloadEnabled        string `gorm:"column:offload_enabled" json:"offload_enabled"`
	OffloadProvider       string `gorm:"column:offload_provider" json:"offload_provider"`
	OffloadAccessKey      string `gorm:"column:offload_access_key" json:"offload_access_key"`
	OffloadSecretKey      string `gorm:"column:offload_secret_key" json:"offload_secret_key"`
	OffloadBucket         string `gorm:"column:offload_bucket" json:"offload_bucket"`
	OffloadPath           string `gorm:"column:offload_path" json:"offload_path"`
	Token                 string `gorm:"column:token" json:"token"`
	PHPMemory             string `gorm:"column:php_memory" json:"php_memory"`
	Storage               string `gorm:"column:storage" json:"storage"`
	Visits                string `gorm:"column:visits" json:"visits"`
	Core                  string `gorm:"column:core" json:"core"`
	CoreVerifyChecksums   string `gorm:"column:core_verify_checksums;default:'1'" json:"core_verify_checksums"`
	SubsiteCount          string `gorm:"column:subsite_count" json:"subsite_count"`
	HomeURL               string `gorm:"column:home_url" json:"home_url"`
	CapturePages          string `gorm:"column:capture_pages;type:text" json:"capture_pages"`
	Themes                string `gorm:"column:themes;type:text" json:"themes"`
	Plugins               string `gorm:"column:plugins;type:text" json:"plugins"`
	Users                 string `gorm:"column:users;type:text" json:"users"`
	Details               string `gorm:"column:details;type:text" json:"details"`
	Screenshot            string `gorm:"column:screenshot" json:"screenshot"`
	MonitorEnabled        string `gorm:"column:monitor_enabled" json:"monitor_enabled"`
	UpdatesEnabled        string `gorm:"column:updates_enabled" json:"updates_enabled"`
	UpdatesExcludeThemes  string `gorm:"column:updates_exclude_themes;type:text" json:"updates_exclude_themes"`
	UpdatesExcludePlugins string `gorm:"column:updates_exclude_plugins;type:text" json:"updates_exclude_plugins"`
}

Environment mirrors captaincore_environments from the PHP schema.

func FindEnvironmentsBySiteID

func FindEnvironmentsBySiteID(siteID uint) ([]Environment, error)

FindEnvironmentsBySiteID returns all environments for a given site ID.

func GetEnvironmentByID

func GetEnvironmentByID(id uint) (*Environment, error)

GetEnvironmentByID returns an environment by its ID.

func (*Environment) ParseDetails

func (e *Environment) ParseDetails() EnvironmentDetails

ParseDetails parses the JSON details column.

func (Environment) TableName

func (Environment) TableName() string

type EnvironmentDetails

type EnvironmentDetails struct {
	Fathom             json.RawMessage `json:"fathom"`
	Auth               *AuthDetails    `json:"auth"`
	ScreenshotBase     string          `json:"screenshot_base"`
	ConsoleErrors      json.RawMessage `json:"console_errors"`
	CapturePluginPages []string        `json:"capture_plugin_pages"`
}

EnvironmentDetails represents the JSON stored in the environment details column.

type FetchSiteMatchingArgs

type FetchSiteMatchingArgs struct {
	Environment string
	Provider    string
	Field       string
	Targets     []string
	Filter      *SiteFilter
}

FetchSiteMatchingArgs holds the arguments for FetchSitesMatching.

type Key

type Key struct {
	KeyID       uint   `gorm:"primaryKey;column:key_id;autoIncrement" json:"key_id"`
	UserID      uint   `gorm:"column:user_id" json:"user_id"`
	Title       string `gorm:"column:title" json:"title"`
	Fingerprint string `gorm:"column:fingerprint" json:"fingerprint"`
	Main        bool   `gorm:"column:main" json:"main"`
	CreatedAt   string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt   string `gorm:"column:updated_at" json:"updated_at"`
}

Key mirrors captaincore_keys from the PHP schema.

func (Key) TableName

func (Key) TableName() string

type MonitorRun

type MonitorRun struct {
	ID               uint    `gorm:"primaryKey;autoIncrement"`
	Command          string  `gorm:"column:command"`
	StartTime        int64   `gorm:"column:start_time"`
	EndTime          int64   `gorm:"column:end_time"`
	Duration         int64   `gorm:"column:duration"`
	SiteCount        int     `gorm:"column:site_count"`
	Parallelism      int     `gorm:"column:parallelism"`
	SystemLoad       float64 `gorm:"column:system_load"`
	Status           string  `gorm:"column:status"`
	ErrorCount       int     `gorm:"column:error_count"`
	RetryAttempts    int     `gorm:"column:retry_attempts"`
	NotificationSent bool    `gorm:"column:notification_sent"`
	RestoredCount    int     `gorm:"column:restored_count"`
}

MonitorRun represents a row in the "runs" table of monitor_stats.db.

func (MonitorRun) TableName

func (MonitorRun) TableName() string

type Provider

type Provider struct {
	ProviderID     uint   `gorm:"primaryKey;column:provider_id;autoIncrement" json:"provider_id,string"`
	UserID         uint   `gorm:"column:user_id" json:"user_id,string"`
	Name           string `gorm:"column:name" json:"name"`
	Provider       string `gorm:"column:provider" json:"provider"`
	Status         string `gorm:"column:status" json:"status"`
	Details        string `gorm:"column:details;type:text" json:"details"`
	Credentials    string `gorm:"column:credentials;type:text" json:"credentials"`
	Configurations string `gorm:"column:configurations;type:text" json:"configurations"`
	CreatedAt      string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt      string `gorm:"column:updated_at" json:"updated_at"`
}

Provider stores hosting provider API credentials (e.g. Kinsta, GridPane).

func GetAllProviders

func GetAllProviders() ([]Provider, error)

GetAllProviders returns all providers ordered by created_at descending.

func GetProviderByID

func GetProviderByID(id uint) (*Provider, error)

GetProviderByID returns a provider by its ID.

func (*Provider) GetCredential

func (p *Provider) GetCredential(name string) string

GetCredential looks up a credential by name from the JSON array stored in Credentials.

func (*Provider) GetCredentialsMap

func (p *Provider) GetCredentialsMap() map[string]string

GetCredentialsMap returns all credentials as a map of name→value.

func (Provider) TableName

func (Provider) TableName() string

type Recipe

type Recipe struct {
	RecipeID  uint   `gorm:"primaryKey;column:recipe_id" json:"recipe_id,string"`
	Title     string `gorm:"column:title" json:"title"`
	Content   string `gorm:"column:content;type:text" json:"content"`
	CreatedAt string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
}

Recipe mirrors captaincore_recipes from the PHP schema.

func GetRecipeByID

func GetRecipeByID(recipeID uint) (*Recipe, error)

GetRecipeByID returns a recipe by its recipe_id.

func (Recipe) TableName

func (Recipe) TableName() string

type Site

type Site struct {
	SiteID         uint   `gorm:"primaryKey;column:site_id;autoIncrement" json:"site_id,string"`
	AccountID      uint   `gorm:"column:account_id" json:"account_id,string"`
	CustomerID     uint   `gorm:"column:customer_id" json:"customer_id,string"`
	Name           string `gorm:"column:name" json:"name"`
	Site           string `gorm:"column:site" json:"site"`
	ProviderID     string `gorm:"column:provider_id" json:"provider_id"`
	ProviderSiteID string `gorm:"column:provider_site_id" json:"provider_site_id"`
	Provider       string `gorm:"column:provider" json:"provider"`
	Token          string `gorm:"column:token" json:"token"`
	Status         string `gorm:"column:status" json:"status"`
	Details        string `gorm:"column:details;type:text" json:"details"`
	Screenshot     string `gorm:"column:screenshot" json:"screenshot"`
	CreatedAt      string `gorm:"column:created_at" json:"created_at"`
	UpdatedAt      string `gorm:"column:updated_at" json:"updated_at"`
}

Site mirrors captaincore_sites from the PHP schema.

func GetAllActiveSites

func GetAllActiveSites() ([]Site, error)

GetAllActiveSites returns all active sites.

func GetSiteByID

func GetSiteByID(id uint) (*Site, error)

GetSiteByID looks up a site by its ID.

func GetSiteByName

func GetSiteByName(name string) (*Site, error)

GetSiteByName looks up an active site by its slug name.

func GetSiteByNameAndProvider

func GetSiteByNameAndProvider(name, provider string) (*Site, error)

GetSiteByNameAndProvider looks up an active site by slug and provider.

func GetSiteByProviderSiteID

func GetSiteByProviderSiteID(providerSiteID, provider string) (*Site, error)

GetSiteByProviderSiteID looks up a site by its provider_site_id and provider slug.

func SearchSites

func SearchSites(search, searchField string) ([]Site, error)

SearchSites searches active sites by LIKE matching on site/name/address columns.

func (*Site) ParseDetails

func (s *Site) ParseDetails() SiteDetails

ParseDetails parses the JSON details column into a SiteDetails struct.

func (Site) TableName

func (Site) TableName() string

type SiteDetails

type SiteDetails struct {
	Key             string          `json:"key"`
	EnvironmentVars json.RawMessage `json:"environment_vars"`
	Subsites        json.RawMessage `json:"subsites"`
	Storage         json.RawMessage `json:"storage"`
	Visits          json.RawMessage `json:"visits"`
	Mailgun         json.RawMessage `json:"mailgun"`
	Core            json.RawMessage `json:"core"`
	Verify          json.RawMessage `json:"verify"`
	RemoteKey       string          `json:"remote_key"`
	BackupSettings  *BackupSettings `json:"backup_settings"`
	ScreenshotBase  string          `json:"screenshot_base"`
	Removed         json.RawMessage `json:"removed"`
	ConsoleErrors   json.RawMessage `json:"console_errors"`
}

SiteDetails represents the JSON stored in the details column.

type SiteEnvironmentResult

type SiteEnvironmentResult struct {
	Site        string `gorm:"column:site"`
	SiteID      uint   `gorm:"column:site_id"`
	Environment string `gorm:"column:environment"`
	// Dynamic field values (populated by extra SELECT columns)
	Name                  string `gorm:"column:name"`
	Provider              string `gorm:"column:provider"`
	HomeURL               string `gorm:"column:home_url"`
	Address               string `gorm:"column:address"`
	Username              string `gorm:"column:username"`
	Port                  string `gorm:"column:port"`
	Core                  string `gorm:"column:core"`
	Themes                string `gorm:"column:themes"`
	Plugins               string `gorm:"column:plugins"`
	UpdatesEnabled        string `gorm:"column:updates_enabled"`
	MonitorEnabled        string `gorm:"column:monitor_enabled"`
	Storage               string `gorm:"column:storage"`
	Visits                string `gorm:"column:visits"`
	HomeDirField          string `gorm:"column:home_directory"`
	DatabaseUsername      string `gorm:"column:database_username"`
	DatabasePassword      string `gorm:"column:database_password"`
	UpdatesExcludeThemes  string `gorm:"column:updates_exclude_themes"`
	UpdatesExcludePlugins string `gorm:"column:updates_exclude_plugins"`
}

SiteEnvironmentResult is a row returned by FetchSitesMatching.

func FetchSitesMatching

func FetchSitesMatching(args FetchSiteMatchingArgs) ([]SiteEnvironmentResult, error)

FetchSitesMatching replicates the PHP Sites::fetch_sites_matching() method. It queries sites joined with environments, applying provider/environment/target filters.

type SiteFilter

type SiteFilter struct {
	Type    string
	Name    string
	Version string
	Status  string
}

SiteFilter holds filter criteria for site listing.

type Snapshot

type Snapshot struct {
	SnapshotID    uint   `gorm:"primaryKey;column:snapshot_id;autoIncrement" json:"snapshot_id"`
	UserID        uint   `gorm:"column:user_id" json:"user_id"`
	SiteID        uint   `gorm:"column:site_id" json:"site_id"`
	EnvironmentID uint   `gorm:"column:environment_id" json:"environment_id"`
	CreatedAt     string `gorm:"column:created_at" json:"created_at"`
	SnapshotName  string `gorm:"column:snapshot_name" json:"snapshot_name"`
	Storage       string `gorm:"column:storage" json:"storage"`
	Email         string `gorm:"column:email" json:"email"`
	Notes         string `gorm:"column:notes;type:text" json:"notes"`
	ExpiresAt     string `gorm:"column:expires_at" json:"expires_at"`
	Token         string `gorm:"column:token" json:"token"`
}

Snapshot mirrors captaincore_snapshots from the PHP schema.

func GetSnapshotByID

func GetSnapshotByID(id uint) (*Snapshot, error)

GetSnapshotByID looks up a snapshot by its ID.

func GetSnapshotsByEnvironmentID

func GetSnapshotsByEnvironmentID(envID uint, limit int) ([]Snapshot, error)

GetSnapshotsByEnvironmentID returns snapshots for an environment, ordered by created_at DESC.

func (Snapshot) TableName

func (Snapshot) TableName() string

Jump to

Keyboard shortcuts

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