Skip to contents

Performs forward-compatible chained schema migration across IR versions ("1.0.0" -> "1.1.0" -> "1.2.0"), populating newly introduced fields with explicit backwards-compatible defaults and attaching an audit trail in attr(result, "migration_log"). Provides crisp specshiny_version_mismatch diagnostics when given an unrecognized or newer future schema version.

Usage

migrate_spec_ir(spec, target_version = SPEC_SCHEMA_VERSION, validate = TRUE)

Arguments

spec

A spec_ir object or named list deserialized from YAML/JSON.

target_version

Character scalar target schema version (defaults to "1.2.0").

validate

Logical; if TRUE (default), validates the migrated spec with assert_valid_spec_ir().

Value

A validated spec_ir object at target_version, with a character vector attr(result, "migration_log") recording applied migration steps.

Examples

legacy <- new_spec_ir(validate = FALSE)
legacy$schema_version <- "1.0.0"
legacy$hierarchy$cluster_size_dist <- NULL
legacy$hierarchy$time_points <- NULL
legacy$outcome$error_dist <- NULL
legacy$outcome$ar1_rho <- NULL
legacy$effects$interactions <- NULL
upgraded <- migrate_spec_ir(legacy)
upgraded$schema_version
#> [1] "1.2.0"
attr(upgraded, "migration_log")
#> [1] "Updated schema_version from '1.0.0' to '1.1.0'."                                    
#> [2] "Initialized hierarchy$cluster_size_dist for balanced clusters."                     
#> [3] "Initialized outcome$error_dist to default Gaussian normal errors."                  
#> [4] "Initialized effects$interactions = list()."                                         
#> [5] "Updated schema_version from '1.1.0' to '1.2.0'."                                    
#> [6] "Initialized optional longitudinal hierarchy$time_points and hierarchy$time_spacing."
#> [7] "Initialized optional outcome$ar1_rho = NULL."