engine

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(dir string) error

Init scaffolds a new migrable project in the given directory. It creates migrable.toml, the migrations directory, and a next/ staging directory.

func Merge

func Merge(migrationsDir string, version string) (string, error)

Merge combines staging files from next/ into a single versioned migration file. Returns the output file path.

func ReadSchemaVersion

func ReadSchemaVersion(filePath string) (*semver.Version, error)

func SplitFileKey

func SplitFileKey(path string, fileKeys []string) (fileKey string, innerPath string, err error)

SplitFileKey splits a dot-separated path into a file key and the inner path within that file. For single-file projects (one key), the full path is returned unchanged as the inner path. For multi-file projects, the first unescaped dot segment must match one of the file keys.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte) error

func WriteFilesAtomic

func WriteFilesAtomic(files map[string][]byte) error

WriteFilesAtomic writes multiple files transactionally. All files are first written to temp files in the same directories as their targets. Only after all temp files are written successfully are they renamed to their final paths. On any failure, all temp files are cleaned up.

func WriteSchemaVersion

func WriteSchemaVersion(filePath string, version *semver.Version) error

Types

type MigrateResult

type MigrateResult struct {
	Applied     int
	FromVersion *semver.Version
	ToVersion   *semver.Version
	// Descriptions maps migration version to its description string.
	Descriptions map[string]string
	// FileChanges maps file key to changes (for dry-run output).
	FileChanges map[string][]tomledit.Change
}

MigrateResult holds the outcome of a Migrate call.

func Migrate

func Migrate(cfg *config.Config, dryRun bool) (*MigrateResult, error)

Migrate applies all pending migrations to the target file(s).

func Rollback

func Rollback(cfg *config.Config, dryRun bool) (*MigrateResult, error)

Rollback reverses the most recently applied migration.

type MigrationMeta

type MigrationMeta struct {
	Version  *semver.Version
	FilePath string
}

func DiscoverMigrations

func DiscoverMigrations(migrationsDir string) ([]MigrationMeta, error)

type RollbackBlockedError

type RollbackBlockedError struct {
	IrreversibleOps []string
}

RollbackBlockedError is returned when a rollback cannot proceed because one or more ops are marked as irreversible.

func (*RollbackBlockedError) Error

func (e *RollbackBlockedError) Error() string

type ValidationIssue

type ValidationIssue struct {
	File    string
	Message string
}

ValidationIssue describes a single problem found during validation.

type ValidationResult

type ValidationResult struct {
	FileCount int
	Errors    []ValidationIssue
	Warnings  []ValidationIssue
}

ValidationResult collects all errors and warnings from validation.

func Validate

func Validate(migrationsDir string) (*ValidationResult, error)

Validate checks all migration files in migrationsDir (and next/ if it exists) for correctness. It collects all issues rather than stopping at the first.

Jump to

Keyboard shortcuts

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