diff --git a/crates/meilitool/src/upgrade/mod.rs b/crates/meilitool/src/upgrade/mod.rs index 4084daead..47ca2cbd9 100644 --- a/crates/meilitool/src/upgrade/mod.rs +++ b/crates/meilitool/src/upgrade/mod.rs @@ -21,7 +21,12 @@ pub struct OfflineUpgrade { impl OfflineUpgrade { pub fn upgrade(self) -> anyhow::Result<()> { let upgrade_list = [ - (v1_9_to_v1_10 as fn(&Path) -> Result<(), anyhow::Error>, "1", "10", "0"), + ( + v1_9_to_v1_10 as fn(&Path, &str, &str, &str) -> Result<(), anyhow::Error>, + "1", + "10", + "0", + ), (v1_10_to_v1_11, "1", "11", "0"), (v1_11_to_v1_12, "1", "12", "0"), (v1_12_to_v1_12_3, "1", "12", "3"), @@ -63,7 +68,7 @@ impl OfflineUpgrade { #[allow(clippy::needless_range_loop)] for index in start_at..=ends_at { let (func, major, minor, patch) = upgrade_list[index]; - (func)(&self.db_path)?; + (func)(&self.db_path, current_major, current_minor, current_patch)?; println!("Done"); // We're writing the version file just in case an issue arise _while_ upgrading. // We don't want the DB to fail in an unknown state. diff --git a/crates/meilitool/src/upgrade/v1_10.rs b/crates/meilitool/src/upgrade/v1_10.rs index 4a49ea471..a35fd4184 100644 --- a/crates/meilitool/src/upgrade/v1_10.rs +++ b/crates/meilitool/src/upgrade/v1_10.rs @@ -151,7 +151,12 @@ fn date_round_trip( Ok(()) } -pub fn v1_9_to_v1_10(db_path: &Path) -> anyhow::Result<()> { +pub fn v1_9_to_v1_10( + db_path: &Path, + _origin_major: &str, + _origin_minor: &str, + _origin_patch: &str, +) -> anyhow::Result<()> { println!("Upgrading from v1.9.0 to v1.10.0"); // 2 changes here diff --git a/crates/meilitool/src/upgrade/v1_11.rs b/crates/meilitool/src/upgrade/v1_11.rs index 92d853dd0..e24a35e8b 100644 --- a/crates/meilitool/src/upgrade/v1_11.rs +++ b/crates/meilitool/src/upgrade/v1_11.rs @@ -14,7 +14,12 @@ use meilisearch_types::milli::index::db_name; use crate::uuid_codec::UuidCodec; use crate::{try_opening_database, try_opening_poly_database}; -pub fn v1_10_to_v1_11(db_path: &Path) -> anyhow::Result<()> { +pub fn v1_10_to_v1_11( + db_path: &Path, + _origin_major: &str, + _origin_minor: &str, + _origin_patch: &str, +) -> anyhow::Result<()> { println!("Upgrading from v1.10.0 to v1.11.0"); let index_scheduler_path = db_path.join("tasks"); diff --git a/crates/meilitool/src/upgrade/v1_12.rs b/crates/meilitool/src/upgrade/v1_12.rs index 513637759..c5463f0b5 100644 --- a/crates/meilitool/src/upgrade/v1_12.rs +++ b/crates/meilitool/src/upgrade/v1_12.rs @@ -23,7 +23,12 @@ use uuid::Uuid; use crate::try_opening_database; use crate::uuid_codec::UuidCodec; -pub fn v1_11_to_v1_12(db_path: &Path) -> anyhow::Result<()> { +pub fn v1_11_to_v1_12( + db_path: &Path, + _origin_major: &str, + _origin_minor: &str, + _origin_patch: &str, +) -> anyhow::Result<()> { println!("Upgrading from v1.11.0 to v1.12.0"); convert_update_files(db_path)?; @@ -31,10 +36,19 @@ pub fn v1_11_to_v1_12(db_path: &Path) -> anyhow::Result<()> { Ok(()) } -pub fn v1_12_to_v1_12_3(db_path: &Path) -> anyhow::Result<()> { +pub fn v1_12_to_v1_12_3( + db_path: &Path, + origin_major: &str, + origin_minor: &str, + origin_patch: &str, +) -> anyhow::Result<()> { println!("Upgrading from v1.12.{{0, 1, 2}} to v1.12.3"); - rebuild_field_distribution(db_path)?; + if origin_minor == "12" { + rebuild_field_distribution(db_path)?; + } else { + println!("Not rebuilding field distribution as it wasn't corrupted coming from v{origin_major}.{origin_minor}.{origin_patch}"); + } Ok(()) }