Documentation
¶
Index ¶
- func Register(m Migration)
- type Migration
- type Registry
- type State
- type StateManager
- func (sm *StateManager) GetProviderVersion() (string, error)
- func (sm *StateManager) IsApplied(name string) (bool, error)
- func (sm *StateManager) Load() (*State, error)
- func (sm *StateManager) MarkApplied(name string) error
- func (sm *StateManager) Save(state *State) error
- func (sm *StateManager) SetProviderVersion(version string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Migration ¶
type Migration interface {
// Name returns a unique identifier for this migration.
// This identifier is used to track whether the migration has been applied.
Name() string
// Description returns a human-readable description of what this migration does.
Description() string
// FromVersion returns the provider version this migration applies from.
// Migrations will only run when upgrading from a version < FromVersion.
// For fresh installs (no previous version), migrations are skipped.
// Return empty string to indicate this migration should always run (not recommended).
FromVersion() string
// Run executes the migration. This method must be idempotent.
// If the migration has already been applied, this should be a no-op.
// The context provides access to Kubernetes clients and other resources.
// The registry tracks applied migrations via the state file, so Run()
// should be safe to call multiple times.
Run(ctx context.Context) error
}
Migration represents a single migration that can be executed. All migrations must be idempotent, running them multiple times should have the same effect as running them once.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages migration discovery and execution.
func NewRegistry ¶
func NewRegistry(stateManager *StateManager) *Registry
NewRegistry creates a new migration registry.
func (*Registry) GetPending ¶
GetPending returns all migrations that have not been applied yet. Migrations are only included if: 1. They haven't been applied (not in state file) 2. The previous provider version is less than or equal to the migration's FromVersion 3. For fresh installs (no previous version), all migrations are marked as applied and skipped
func (*Registry) RunMigrations ¶
RunMigrations executes all pending migrations. Returns the number of migrations that were successfully executed. After successful execution, updates the provider version and applied migrations in state.
func (*Registry) SetCurrentVersion ¶
SetCurrentVersion sets the current provider version. This should be called before GetPending or RunMigrations.
type State ¶
type State struct {
Applied []string `json:"applied"`
LastRun time.Time `json:"last_run"`
ProviderVersion string `json:"provider_version,omitempty"`
}
State represents the state of executed migrations.
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager handles reading and writing migration state to a file.
func NewStateManager ¶
func NewStateManager(statePath string) *StateManager
NewStateManager creates a new StateManager with the given state file path.
func (*StateManager) GetProviderVersion ¶
func (sm *StateManager) GetProviderVersion() (string, error)
GetProviderVersion returns the provider version from the state.
func (*StateManager) IsApplied ¶
func (sm *StateManager) IsApplied(name string) (bool, error)
IsApplied checks if a migration with the given name has been applied.
func (*StateManager) Load ¶
func (sm *StateManager) Load() (*State, error)
Load reads the migration state from the file. If the file doesn't exist, returns an empty state.
func (*StateManager) MarkApplied ¶
func (sm *StateManager) MarkApplied(name string) error
MarkApplied adds a migration name to the applied list and saves the state.
func (*StateManager) Save ¶
func (sm *StateManager) Save(state *State) error
Save writes the migration state to the file. Creates the directory if it doesn't exist.
func (*StateManager) SetProviderVersion ¶
func (sm *StateManager) SetProviderVersion(version string) error
SetProviderVersion sets the provider version in the state.