Documentation
¶
Index ¶
- Variables
- func Checkpoint()
- func CountSnapshotsByEnvironmentID(envID uint) (int64, error)
- func DeleteAccountByID(accountID uint) error
- func DeleteAccountSiteByID(id uint) error
- func DeleteDomainByID(id uint) error
- func DeleteEnvironmentByID(envID uint) error
- func DeleteProviderByID(id uint) error
- func DeleteSiteByID(siteID uint) error
- func GetConfiguration(captainID uint, key string) (string, error)
- func GetSystemLoad() float64
- func InitDB() error
- func InitMonitorDB() error
- func InsertSnapshot(snapshot *Snapshot) error
- func LogMonitorRunEnd(runID uint, siteCount, errorCount, retryAttempts, restoredCount int, ...)
- func LogMonitorRunSkipped(parallelism int)
- func LogMonitorRunStart(command string, parallelism int) uint
- func ParseTargetString(target string) (environment string, minorTargets []string)
- func SetConfiguration(captainID uint, key, value string) error
- func UpsertAccount(account Account) error
- func UpsertAccountDomain(ad AccountDomain) error
- func UpsertAccountSite(as AccountSite) error
- func UpsertAccountUser(au AccountUser) error
- func UpsertConnection(conn Connection) error
- func UpsertDomain(d Domain) error
- func UpsertEnvironment(env Environment, skipUsers bool) error
- func UpsertProvider(p Provider) error
- func UpsertRecipe(recipe *Recipe) error
- func UpsertSite(site Site) error
- type Account
- type AccountDomain
- type AccountSite
- type AccountUser
- type AuthDetails
- type BackupSettings
- type Capture
- type Configuration
- type Connection
- type Domain
- type Environment
- type EnvironmentDetails
- type FetchSiteMatchingArgs
- type Key
- type MonitorRun
- type Provider
- type Recipe
- type Site
- func GetAllActiveSites() ([]Site, error)
- func GetSiteByID(id uint) (*Site, error)
- func GetSiteByName(name string) (*Site, error)
- func GetSiteByNameAndProvider(name, provider string) (*Site, error)
- func GetSiteByProviderSiteID(providerSiteID, provider string) (*Site, error)
- func SearchSites(search, searchField string) ([]Site, error)
- type SiteDetails
- type SiteEnvironmentResult
- type SiteFilter
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
var DB *gorm.DB
DB is the global database connection used by all model queries.
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 ¶
CountSnapshotsByEnvironmentID returns the number of snapshots for an environment.
func DeleteAccountByID ¶
DeleteAccountByID removes an account and its related junction table records.
func DeleteAccountSiteByID ¶
DeleteAccountSiteByID removes an account_site junction row by its primary key.
func DeleteDomainByID ¶
DeleteDomainByID removes a domain record by its ID.
func DeleteEnvironmentByID ¶
DeleteEnvironmentByID removes an environment record by its ID.
func DeleteProviderByID ¶
DeleteProviderByID removes a provider record by its ID.
func DeleteSiteByID ¶
DeleteSiteByID removes a site and its related environments and account_site records.
func GetConfiguration ¶
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 ¶
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 ¶
LogMonitorRunStart inserts a new run record with status "running" and returns its ID.
func ParseTargetString ¶
ParseTargetString parses a target string like "@production.monitor-on" into environment and minor target components.
func SetConfiguration ¶
SetConfiguration upserts a configuration value.
func UpsertAccount ¶
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 ¶
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 ¶
UpsertProvider inserts or updates a provider record by provider_id.
func UpsertRecipe ¶
UpsertRecipe inserts or updates a recipe by recipe_id.
func UpsertSite ¶
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 ¶
GetAccountByID returns an account by its ID.
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 BackupSettings ¶
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.
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.
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.
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 ¶
GetAllProviders returns all providers ordered by created_at descending.
func GetProviderByID ¶
GetProviderByID returns a provider by its ID.
func (*Provider) GetCredential ¶
GetCredential looks up a credential by name from the JSON array stored in Credentials.
func (*Provider) GetCredentialsMap ¶
GetCredentialsMap returns all credentials as a map of name→value.
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 ¶
GetRecipeByID returns a recipe by its recipe_id.
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 ¶
GetAllActiveSites returns all active sites.
func GetSiteByName ¶
GetSiteByName looks up an active site by its slug name.
func GetSiteByNameAndProvider ¶
GetSiteByNameAndProvider looks up an active site by slug and provider.
func GetSiteByProviderSiteID ¶
GetSiteByProviderSiteID looks up a site by its provider_site_id and provider slug.
func SearchSites ¶
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.
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 ¶
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 ¶
GetSnapshotByID looks up a snapshot by its ID.
func GetSnapshotsByEnvironmentID ¶
GetSnapshotsByEnvironmentID returns snapshots for an environment, ordered by created_at DESC.