Documentation
¶
Overview ¶
Package migrationartifact owns atomic, immutable migration artifact files.
Index ¶
- Constants
- Variables
- func AdoptionEnd(files []File, applied int, blockingStep func(File) string, ...) (int, error)
- func CheckReplacement(files, previous []File, applied int, blockingStep func(File) string) (int, error)
- func HistoryDigest(files []File) (string, error)
- func LatestManifest(directory string) (schema.Manifest, bool, error)
- func PreviousHistoryError(err error) error
- func RemovedResources(old, replacement schema.Snapshot) []schema.StableID
- func ReplacementHistories(directory string, options migration.BaselineReplacementOptions) ([]File, []File, error)
- func ReplacementSchemaDriftError(err error) error
- func RequireRetainedResources(old, replacement schema.Snapshot) error
- func SameRecordedHistory(files, previous []File, applied int) bool
- type File
- func Create(directory, name string, artifact migration.Artifact, now time.Time) (File, error)
- func ReadAll(directory string) ([]File, error)
- func RequireCurrentHistory(directory string, executable schema.Manifest) ([]File, error)
- func RequireCurrentHistoryForPlanner(directory string, executable schema.Manifest, plannerName string) ([]File, error)
Constants ¶
const Extension = ".ridu.json"
Extension distinguishes Ridu artifacts from arbitrary JSON.
Variables ¶
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) )
var ErrNoRecordedHistory = errors.New("no recorded history to replace; use ridu migrate baseline")
ErrNoRecordedHistory refuses a replacement for a database without a ledger.
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
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 ¶
LatestManifest returns the desired schema committed by the newest artifact.
func PreviousHistoryError ¶ added in v0.12.0
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
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
ReplacementSchemaDriftError explains a database whose physical schema does not match the replacement head the ledger would record.
func RequireRetainedResources ¶ added in v0.12.0
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
SameRecordedHistory identifies a replacement which already exactly matches.
Types ¶
type File ¶
File contains one parsed immutable migration and its filesystem identity.
func Create ¶
Create atomically creates one migration artifact and never overwrites an existing filename.
func RequireCurrentHistory ¶
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.