Version: v0.11.0

can_migrate

Stable function · Versions and migration

Tier: stable · Kind: function · Topic: Versions and migration

JuliaTypeScriptPythonRustGo
can_migratecanMigratecan_migratecan_migrateCanMigrate

Julia

can_migrate(from_version::AbstractString, to_version::AbstractString)
can_migrate(file::EsmFile, to_version::AbstractString)
can_migrate(doc::AbstractDict, to_version::AbstractString)
can_migrate(from_version::AbstractString, to_version::AbstractString) -> Bool

Whether this version pair is supported — i.e. whether to_version is among supported_migration_targets (from_version). For a 1.x source that is a necessary condition only: the document must also use none of the constructs esm 2.0.0 removed, which the document forms below check.

can_migrate(file::EsmFile, to_version) -> Bool
can_migrate(doc::AbstractDict, to_version) -> Bool

Whether migrate would succeed for this document: the version pair is supported and, for a 1.x source, the document uses no removed construct. A caller told true is never then handed a MigrationError.

Source

TypeScript

function canMigrate(sourceVersion: string, targetVersion: string): boolean

Check if migration is possible from the source version to target version.

Source

Python

can_migrate(from_version: str, to_version: str) -> bool

True when migrate could succeed for this version pair (a 1.x source still fails when it uses a removed operator).

Source

Rust

pub fn can_migrate(from_version: &str, to_version: &str) -> bool

Whether migrate supports this version pair — i.e. whether to_version is among supported_migration_targets (from_version).

Deliberately consults the same single source of truth migrate does, so a caller is never told a pair is migratable and then handed a MigrationError for the versions. The one content check is the 1.x → 2.0.0 step: migrate refuses a document that uses an op 2.0.0 removed.

Source · Rust docs

Example (migrate)

// decay.esm is written at format 1.0.0; the current format is a newer
// 1.x, reached by a version-marker bump with no structural change.
assert_eq!(doc.esm, "1.0.0");
assert_eq!(supported_migration_targets(&doc.esm), [SCHEMA_VERSION]);
assert!(can_migrate(&doc.esm, SCHEMA_VERSION));
let migrated = migrate(&doc, SCHEMA_VERSION)?;
assert_eq!(migrated.esm, SCHEMA_VERSION);

// A 0.x document is out of reach: 1.0.0 was a clean break.
assert!(!can_migrate("0.9.0", SCHEMA_VERSION));

From docs/api/examples/rust/load.rs

Go

func CanMigrate(sourceVersion, targetVersion string) bool

CanMigrate reports whether a migration from sourceVersion to targetVersion is supported.

Source · Go docs