can_migrate
Stable function · Versions and migration
Tier: stable · Kind: function · Topic: Versions and migration
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
can_migrate | canMigrate | can_migrate | can_migrate | CanMigrate |
Julia
can_migrate(from_version::AbstractString, to_version::AbstractString)
can_migrate(from_version::AbstractString, to_version::AbstractString) -> Bool
Whether migrate
would succeed for 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.
TypeScript
function canMigrate(sourceVersion: string, targetVersion: string): boolean
Check if migration is possible from the source version to target version.
Python
can_migrate(from_version: str, to_version: str) -> bool
True when migrate
would succeed for this version pair.
Rust
pub fn can_migrate(from_version: &str, to_version: &str) -> bool
Whether migrate
would succeed for 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
.
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));