upgrade

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package upgrade provides functionality for upgrading Buffalo and migrating configurations.

Index

Constants

View Source
const (
	// GitHubAPIURL is the base URL for GitHub API.
	GitHubAPIURL = "https://api.github.com"

	// DefaultOwner is the default GitHub repository owner.
	DefaultOwner = "massonsky"

	// DefaultRepo is the default GitHub repository name.
	DefaultRepo = "buffalo"
)

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(v1, v2 string) int

CompareVersions is exported for external use.

func DetectConfigVersion

func DetectConfigVersion(configPath string) (string, error)

DetectConfigVersion attempts to detect the Buffalo version a config was created for.

func FormatChangelog

func FormatChangelog(body string, width int) string

FormatChangelog formats release notes for display.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker checks for Buffalo updates.

func NewChecker

func NewChecker(opts ...CheckerOption) *Checker

NewChecker creates a new update checker.

func (*Checker) CheckForUpdates

func (c *Checker) CheckForUpdates(ctx context.Context) (*UpgradeCheck, error)

CheckForUpdates checks if a newer version is available.

func (*Checker) GetAssetForPlatform

func (c *Checker) GetAssetForPlatform(release *ReleaseInfo) (*ReleaseAsset, error)

GetAssetForPlatform finds the appropriate asset for the current platform.

func (*Checker) GetChangelogBetweenVersions

func (c *Checker) GetChangelogBetweenVersions(ctx context.Context, fromVersion, toVersion string) (string, error)

GetChangelogBetweenVersions returns changelog for versions between from and to.

func (*Checker) GetLatestRelease

func (c *Checker) GetLatestRelease(ctx context.Context) (*ReleaseInfo, error)

GetLatestRelease fetches the latest release from GitHub.

func (*Checker) GetRelease

func (c *Checker) GetRelease(ctx context.Context, tag string) (*ReleaseInfo, error)

GetRelease fetches a specific release by tag.

func (*Checker) GetReleases

func (c *Checker) GetReleases(ctx context.Context, includePrerelease bool) ([]*ReleaseInfo, error)

GetReleases fetches all releases from GitHub.

type CheckerOption

type CheckerOption func(*Checker)

CheckerOption is a functional option for Checker.

func WithAPIBaseURL

func WithAPIBaseURL(url string) CheckerOption

WithAPIBaseURL sets a custom API base URL (for testing).

func WithHTTPClient

func WithHTTPClient(client *http.Client) CheckerOption

WithHTTPClient sets a custom HTTP client.

func WithRepository

func WithRepository(owner, repo string) CheckerOption

WithRepository sets a custom GitHub repository.

type Migration

type Migration struct {
	// FromVersion is the minimum version this migration applies to.
	FromVersion string
	// ToVersion is the target version after migration.
	ToVersion string
	// Description describes what this migration does.
	Description string
	// Component is the component being migrated.
	Component string
	// Breaking indicates if this is a breaking change.
	Breaking bool
	// Apply is the function that performs the migration.
	Apply func(data map[string]interface{}) error
}

Migration represents a configuration migration between versions.

type MigrationResult

type MigrationResult struct {
	// Success indicates if migration was successful.
	Success bool
	// Steps contains the executed migration steps.
	Steps []MigrationStepResult
	// BackupPath is the path to the backup (if created).
	BackupPath string
	// Errors contains any errors that occurred.
	Errors []error
}

MigrationResult contains the result of a migration.

type MigrationStep

type MigrationStep struct {
	// Component being migrated (e.g., "buffalo.yaml", "plugins").
	Component string
	// Description of what will change.
	Description string
	// FromVersion is the source version.
	FromVersion string
	// ToVersion is the target version.
	ToVersion string
	// Breaking indicates if this is a breaking change.
	Breaking bool
}

MigrationStep describes a single migration action.

type MigrationStepResult

type MigrationStepResult struct {
	// Step is the migration step that was executed.
	Step MigrationStep
	// Success indicates if this step was successful.
	Success bool
	// Error contains any error that occurred.
	Error error
	// Changes describes what was changed.
	Changes []string
}

MigrationStepResult contains the result of a single migration step.

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator handles configuration migrations between Buffalo versions.

func NewMigrator

func NewMigrator(backupDir string) *Migrator

NewMigrator creates a new configuration migrator.

func (*Migrator) GetApplicableMigrations

func (m *Migrator) GetApplicableMigrations(fromVersion, toVersion string) []Migration

GetApplicableMigrations returns migrations needed to go from fromVersion to toVersion.

func (*Migrator) GetMigrationSteps

func (m *Migrator) GetMigrationSteps(fromVersion, toVersion string) []MigrationStep

GetMigrationSteps returns migration steps without applying them.

func (*Migrator) LoadRollbackInfo

func (m *Migrator) LoadRollbackInfo() (*RollbackInfo, error)

LoadRollbackInfo loads the most recent rollback information.

func (*Migrator) Migrate

func (m *Migrator) Migrate(configPath string, fromVersion, toVersion string, dryRun bool) (*MigrationResult, error)

Migrate applies all applicable migrations to the config file.

func (*Migrator) Rollback

func (m *Migrator) Rollback(configPath string) error

Rollback restores the previous configuration from backup.

func (*Migrator) SaveRollbackInfo

func (m *Migrator) SaveRollbackInfo(info *RollbackInfo) error

SaveRollbackInfo saves rollback information for later use.

func (*Migrator) ValidateConfig

func (m *Migrator) ValidateConfig(configPath string) error

ValidateConfig validates a config file after migration.

type ReleaseAsset

type ReleaseAsset struct {
	// Name is the asset filename.
	Name string `json:"name"`
	// Size is the asset size in bytes.
	Size int64 `json:"size"`
	// DownloadURL is the URL to download the asset.
	DownloadURL string `json:"browser_download_url"`
	// ContentType is the MIME type of the asset.
	ContentType string `json:"content_type"`
}

ReleaseAsset represents a downloadable asset in a release.

type ReleaseInfo

type ReleaseInfo struct {
	// Version is the release version (e.g., "5.0.0").
	Version string `json:"tag_name"`
	// Name is the release name.
	Name string `json:"name"`
	// Body is the release notes/changelog.
	Body string `json:"body"`
	// PublishedAt is when the release was published.
	PublishedAt time.Time `json:"published_at"`
	// HTMLURL is the URL to the release page.
	HTMLURL string `json:"html_url"`
	// Prerelease indicates if this is a pre-release.
	Prerelease bool `json:"prerelease"`
	// Draft indicates if this is a draft release.
	Draft bool `json:"draft"`
	// Assets contains the release assets (binaries).
	Assets []ReleaseAsset `json:"assets"`
}

ReleaseInfo contains information about a Buffalo release.

type RollbackInfo

type RollbackInfo struct {
	// Timestamp when the upgrade was performed.
	Timestamp time.Time `json:"timestamp"`
	// FromVersion is the version before upgrade.
	FromVersion string `json:"from_version"`
	// ToVersion is the version after upgrade.
	ToVersion string `json:"to_version"`
	// BackupPath is the path to the backup.
	BackupPath string `json:"backup_path"`
	// BinaryBackupPath is the path to the binary backup.
	BinaryBackupPath string `json:"binary_backup_path"`
}

RollbackInfo contains information about a previous upgrade for rollback.

type UpgradeCheck

type UpgradeCheck struct {
	// CurrentVersion is the currently installed version.
	CurrentVersion string
	// LatestVersion is the latest available version.
	LatestVersion string
	// UpdateAvailable indicates if an update is available.
	UpdateAvailable bool
	// LatestRelease contains full release information.
	LatestRelease *ReleaseInfo
	// MigrationSteps lists what will be migrated.
	MigrationSteps []MigrationStep
}

UpgradeCheck contains the result of checking for updates.

type UpgradeOptions

type UpgradeOptions struct {
	// TargetVersion is the version to upgrade to (empty for latest).
	TargetVersion string
	// DryRun if true, only shows what would change without applying.
	DryRun bool
	// Force if true, skips confirmation prompts.
	Force bool
	// SkipBinaryUpgrade if true, only migrates configs without updating binary.
	SkipBinaryUpgrade bool
	// SkipConfigMigration if true, only updates binary without migrating configs.
	SkipConfigMigration bool
	// CreateBackup if true, creates backup before migration.
	CreateBackup bool
	// BackupDir is the directory for backups.
	BackupDir string
	// ConfigPath is the path to buffalo.yaml.
	ConfigPath string
}

UpgradeOptions contains options for the upgrade process.

type Upgrader

type Upgrader struct {
	// contains filtered or unexported fields
}

Upgrader handles the upgrade process.

func NewUpgrader

func NewUpgrader(log *logger.Logger, backupDir string, opts ...CheckerOption) *Upgrader

NewUpgrader creates a new upgrader.

func (*Upgrader) Check

func (u *Upgrader) Check(ctx context.Context) (*UpgradeCheck, error)

Check checks for available updates.

func (*Upgrader) CheckVersion

func (u *Upgrader) CheckVersion(ctx context.Context, targetVersion string) (*UpgradeCheck, error)

CheckVersion checks for a specific version.

func (*Upgrader) GetChangelog

func (u *Upgrader) GetChangelog(ctx context.Context, fromVersion, toVersion string) (string, error)

GetChangelog returns the changelog between versions.

func (*Upgrader) Rollback

func (u *Upgrader) Rollback(configPath string) error

Rollback rolls back to the previous version.

func (*Upgrader) Upgrade

func (u *Upgrader) Upgrade(ctx context.Context, opts UpgradeOptions) (*MigrationResult, error)

Upgrade performs the upgrade to the specified version.

Jump to

Keyboard shortcuts

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