Skip to content

Commit

Permalink
Allow compatible upgrade from rc to minor versions (#1498)
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen authored Feb 24, 2025
1 parent 949c230 commit 369f0d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/portable/instance/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn upgrade_local_cmd(cmd: &Command, name: &str) -> anyhow::Result<()> {
// we rely on presence of the version specifying options instead to
// define how we want upgrade to be performed. This is mostly useful
// for tests.
if pkg_ver.is_compatible(&inst_ver) && !(cmd.force && ver_option) && !cmd.force_dump_restore {
if inst_ver.is_compatible(&pkg_ver) && !(cmd.force && ver_option) && !cmd.force_dump_restore {
upgrade_compatible(inst, pkg)
} else {
upgrade_incompatible(inst, pkg, cmd.non_interactive)
Expand Down
2 changes: 1 addition & 1 deletion src/portable/project/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn upgrade_local(
// since some selector like `--to-latest` was specified we assume
// user want to treat this upgrade as incompatible and do the
// upgrade. This is mostly for testing.
if pkg_ver.is_compatible(&inst_ver) && !cmd.force {
if inst_ver.is_compatible(&pkg_ver) && !cmd.force {
upgrade::upgrade_compatible(inst, pkg)?;
} else {
migrations::upgrade_check::to_version(&pkg, project)?;
Expand Down
43 changes: 40 additions & 3 deletions src/portable/ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,20 @@ impl Filter {
impl Specific {
pub fn is_compatible(&self, other: &Specific) -> bool {
use MinorVersion::*;

if self.major != other.major {
return false;
}

// when major versions match
match (&self.minor, &other.minor) {
(Minor(_), Minor(_)) if self.major == other.major => true,
// all dev/alpha/rc are incompatible as well as different major
// but fully matching versions are always compatible
// rc can be upgraded to any rc or minor
(Rc(_), Rc(_) | Minor(_)) => true,

// minor can be upgraded to any minor
(Minor(_), Minor(_)) => true,

// all other cases: upgrade only in exact match
_ => self == other,
}
}
Expand Down Expand Up @@ -441,3 +451,30 @@ fn filter() {
}
);
}

#[test]
fn is_compatible() {
assert!(Specific::from_str("6.0-rc.3")
.unwrap()
.is_compatible(&Specific::from_str("6.0").unwrap()));

assert!(Specific::from_str("6.0-rc.3")
.unwrap()
.is_compatible(&Specific::from_str("6.0-rc.2").unwrap()));

assert!(Specific::from_str("6.0-rc.2")
.unwrap()
.is_compatible(&Specific::from_str("6.0-rc.3").unwrap()));

assert!(!Specific::from_str("5.0-rc.2")
.unwrap()
.is_compatible(&Specific::from_str("6.0-rc.3").unwrap()));

assert!(Specific::from_str("6.0")
.unwrap()
.is_compatible(&Specific::from_str("6.1").unwrap()));

assert!(Specific::from_str("6.2")
.unwrap()
.is_compatible(&Specific::from_str("6.1").unwrap()));
}

0 comments on commit 369f0d1

Please sign in to comment.