Documentation
¶
Index ¶
- Variables
- func ComputeSchemaHash(cfg config.Config) string
- func ListBackups(rootDir string) ([]string, error)
- func NeedsMigration(targetDir string) (bool, string, string, error)
- func RestoreBackup(rootDir, backupDir string) error
- func SchemaVersionMatches(cfg config.Config) bool
- type BackupResult
- type Executor
- type ExecutorOptions
- type ExecutorResult
- type Migration
- type Registry
- type TransformFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the global migration registry.
Functions ¶
func ComputeSchemaHash ¶
ComputeSchemaHash computes a deterministic SHA-256 hash of the schema configuration. It includes CustomBlockTypes and SchemaRules, using sorted keys for determinism. Returns the first 16 hex characters (64 bits) for readability. Returns empty string if no schema constraints are defined.
func ListBackups ¶
ListBackups returns a list of available backup directories.
func NeedsMigration ¶
NeedsMigration checks if the project needs schema migration.
func RestoreBackup ¶
RestoreBackup restores a project from a backup directory. It replaces the current config.yaml and nodes/ with the backup contents.
func SchemaVersionMatches ¶
SchemaVersionMatches checks if the config's SchemaVersion matches the computed hash. Returns true if they match or if there are no schema constraints.
Types ¶
type BackupResult ¶
type BackupResult struct {
// BackupDir is the full path to the backup directory.
BackupDir string
// Timestamp is when the backup was created.
Timestamp time.Time
// NodeCount is the number of node files backed up.
NodeCount int
}
BackupResult contains information about a created backup.
func CreateBackup ¶
func CreateBackup(rootDir string) (*BackupResult, error)
CreateBackup creates a backup of the current project state. It creates a .deco/backup-<timestamp>/ directory containing: - config.yaml (copy of current config) - nodes/ (copy of all node files)
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor performs schema migrations.
func NewExecutor ¶
func NewExecutor(opts ExecutorOptions, registry *Registry) *Executor
NewExecutor creates a new migration executor.
func (*Executor) Execute ¶
func (e *Executor) Execute() (*ExecutorResult, error)
Execute runs the migration from current schema to target schema.
type ExecutorOptions ¶
type ExecutorOptions struct {
// DryRun if true, shows what would change without making changes.
DryRun bool
// NoBackup if true, skips creating a backup before migration.
NoBackup bool
// Quiet if true, suppresses non-essential output.
Quiet bool
// TargetDir is the project root directory.
TargetDir string
}
ExecutorOptions configures the migration executor.
type ExecutorResult ¶
type ExecutorResult struct {
// NodesProcessed is the number of nodes processed.
NodesProcessed int
// NodesModified is the number of nodes that were actually changed.
NodesModified int
// BackupDir is the path to the backup (if created).
BackupDir string
// SourceHash is the schema hash before migration.
SourceHash string
// TargetHash is the schema hash after migration.
TargetHash string
// DryRun indicates if this was a dry run.
DryRun bool
}
ExecutorResult contains the result of a migration execution.
type Migration ¶
type Migration struct {
// Name is a unique identifier for this migration.
Name string
// Description explains what this migration does.
Description string
// SourceHash is the schema hash this migration applies to.
// Empty string matches any source (useful for initial migrations).
SourceHash string
// TargetHash is the schema hash after this migration.
TargetHash string
// Transform is the function that transforms each node.
// If nil, this is an identity migration (updates schema version only).
Transform TransformFunc
}
Migration represents a single schema migration.
func IdentityMigration ¶
IdentityMigration creates a migration that updates schema version without transforming nodes. Useful when schema changes are additive (new optional fields) and nodes don't need modification.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages available migrations.
func (*Registry) Clear ¶
func (r *Registry) Clear()
Clear removes all migrations from the registry. Primarily useful for testing.
func (*Registry) Find ¶
Find returns a migration that transforms from sourceHash to targetHash. Returns nil if no direct migration exists.
func (*Registry) FindPath ¶
FindPath returns a sequence of migrations to get from sourceHash to targetHash. Uses breadth-first search to find the shortest path. Returns nil if no path exists.