migrationartifact

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package migrationartifact owns atomic, immutable migration artifact files.

Index

Constants

View Source
const Extension = ".ridu.json"

Extension distinguishes Ridu artifacts from arbitrary JSON.

Variables

View Source
var (
	// ErrSchemaCurrent reports that a new migration would record nothing:
	// the schema is the one the latest migration records.
	ErrSchemaCurrent = errors.New("schema is current")
	// ErrOnlyPresentationChanges reports that the schema differs from the
	// latest migration only outside its storage schema, which history ignores.
	ErrOnlyPresentationChanges = fmt.Errorf("%w; only presentation settings changed, so no migration is needed", ErrSchemaCurrent)
)
View Source
var ErrNoRecordedHistory = errors.New("no recorded history to replace; use ridu migrate baseline")

ErrNoRecordedHistory refuses a replacement for a database without a ledger.

View Source
var ErrReplacementPartlyApplied = errors.New("a migration is partly applied; finish it with the original history before replacing the baseline")

ErrReplacementPartlyApplied refuses a replacement while recorded work is incomplete: only the original artifacts can finish it.

Functions

func AdoptionEnd added in v0.9.0

func AdoptionEnd(files []File, applied int, blockingStep func(File) string, matches func(index int) (bool, error)) (int, error)

AdoptionEnd decides how much of a pending history a baseline may record as applied without running it, on a database that schema sync already brought forward. It returns the history length after adoption: the newest artifact whose resulting schema the database has, provided no artifact up to it has a step schema sync never runs. Later artifacts stay pending for ridu migrate up.

matches reports whether the database's physical schema equals the schema after files[index]; blockingStep names a step that only a migration runner performs, or returns "" when every step is physical.

func CheckReplacement added in v0.12.0

func CheckReplacement(files, previous []File, applied int, blockingStep func(File) string) (int, error)

CheckReplacement refuses to forget data/semantic work and returns how many replacement artifacts the ledger can record. Recorded data/semantic artifacts must survive unchanged at the same history position. The first replacement artifact with such a step that the database has not recorded unchanged ends the recordable prefix: it and every later artifact stay pending for ridu migrate up.

func HistoryDigest added in v0.15.0

func HistoryDigest(files []File) (string, error)

HistoryDigest returns the executable migration history digest that `ridu build` links into a production server: the ordered artifact identities, recorded head digest and storage schema of the newest artifact.

func LatestManifest

func LatestManifest(directory string) (schema.Manifest, bool, error)

LatestManifest returns the desired schema committed by the newest artifact.

func PreviousHistoryError added in v0.12.0

func PreviousHistoryError(err error) error

PreviousHistoryError explains how to recover the evidence needed to rewrite a divergent ledger safely without direct database edits.

func RemovedResources added in v0.12.0

func RemovedResources(old, replacement schema.Snapshot) []schema.StableID

RemovedResources lists the collections and globals in the recorded head that the replacement head no longer has. A real migration retires their framework-owned state (versions, references, uniqueness); a ledger replacement cannot.

func ReplacementHistories added in v0.12.0

func ReplacementHistories(directory string, options migration.BaselineReplacementOptions) ([]File, []File, error)

ReplacementHistories reads the replacement and the evidence for recorded history. A checksum alone cannot establish whether a deleted artifact ran data steps, so divergent histories must provide the original artifacts.

func ReplacementSchemaDriftError added in v0.12.0

func ReplacementSchemaDriftError(err error) error

ReplacementSchemaDriftError explains a database whose physical schema does not match the replacement head the ledger would record.

func RequireRetainedResources added in v0.12.0

func RequireRetainedResources(old, replacement schema.Snapshot) error

RequireRetainedResources refuses a replacement that would claim the removal of a collection or global ran without retiring its framework-owned state.

func SameRecordedHistory added in v0.12.0

func SameRecordedHistory(files, previous []File, applied int) bool

SameRecordedHistory identifies a replacement which already exactly matches.

Types

type File

type File struct {
	Path     string
	Name     string
	Digest   string
	Artifact migration.Artifact
}

File contains one parsed immutable migration and its filesystem identity.

func Create

func Create(directory, name string, artifact migration.Artifact, now time.Time) (File, error)

Create atomically creates one migration artifact and never overwrites an existing filename.

func ReadAll

func ReadAll(directory string) ([]File, error)

ReadAll parses, validates, and returns artifacts in lexical execution order.

func RequireCurrentHistory

func RequireCurrentHistory(directory string, executable schema.Manifest) ([]File, error)

RequireCurrentHistory proves that a deployable executable manifest is the exact head of a non-empty, immutable artifact history. An empty history is a valid input only to migration creation; release checks and database commands must fail closed until the initial artifact has been created and committed.

func RequireCurrentHistoryForPlanner

func RequireCurrentHistoryForPlanner(directory string, executable schema.Manifest, plannerName string) ([]File, error)

RequireCurrentHistoryForPlanner additionally proves that every immutable artifact belongs to the planner family selected by the project database. Adapter runners retain ownership of planner-version and exact-plan checks.

Jump to

Keyboard shortcuts

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