diff --git a/crates/milli/src/update/upgrade/mod.rs b/crates/milli/src/update/upgrade/mod.rs index 16f0eef7a..0ed67f2cb 100644 --- a/crates/milli/src/update/upgrade/mod.rs +++ b/crates/milli/src/update/upgrade/mod.rs @@ -3,7 +3,7 @@ mod v1_13; use heed::RwTxn; use v1_12::{V1_12_3_To_V1_13_0, V1_12_To_V1_12_3}; -use v1_13::V1_13_0_To_Current; +use v1_13::{V1_13_0_To_V1_13_1, V1_13_1_To_Current}; use crate::progress::{Progress, VariableNameStep}; use crate::{Index, InternalError, Result}; @@ -28,13 +28,18 @@ pub fn upgrade( progress: Progress, ) -> Result { let from = index.get_version(wtxn)?.unwrap_or(db_version); - let upgrade_functions: &[&dyn UpgradeIndex] = - &[&V1_12_To_V1_12_3 {}, &V1_12_3_To_V1_13_0 {}, &V1_13_0_To_Current()]; + let upgrade_functions: &[&dyn UpgradeIndex] = &[ + &V1_12_To_V1_12_3 {}, + &V1_12_3_To_V1_13_0 {}, + &V1_13_0_To_V1_13_1 {}, + &V1_13_1_To_Current {}, + ]; let start = match from { (1, 12, 0..=2) => 0, (1, 12, 3..) => 1, (1, 13, 0) => 2, + (1, 13, 1) => 3, // We must handle the current version in the match because in case of a failure some index may have been upgraded but not other. (1, 13, _) => return Ok(false), (major, minor, patch) => { diff --git a/crates/milli/src/update/upgrade/v1_13.rs b/crates/milli/src/update/upgrade/v1_13.rs index 52246a7f3..f1d56d9cb 100644 --- a/crates/milli/src/update/upgrade/v1_13.rs +++ b/crates/milli/src/update/upgrade/v1_13.rs @@ -2,13 +2,44 @@ use heed::RwTxn; use super::UpgradeIndex; use crate::constants::{VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH}; +use crate::database_stats::DatabaseStats; use crate::progress::Progress; -use crate::{Index, Result}; +use crate::{make_enum_progress, Index, Result}; #[allow(non_camel_case_types)] -pub(super) struct V1_13_0_To_Current(); +pub(super) struct V1_13_0_To_V1_13_1(); -impl UpgradeIndex for V1_13_0_To_Current { +impl UpgradeIndex for V1_13_0_To_V1_13_1 { + fn upgrade( + &self, + wtxn: &mut RwTxn, + index: &Index, + _original: (u32, u32, u32), + progress: Progress, + ) -> Result { + make_enum_progress! { + enum DocumentsStats { + CreatingDocumentsStats, + } + }; + + // Create the new documents stats. + progress.update_progress(DocumentsStats::CreatingDocumentsStats); + let stats = DatabaseStats::new(index.documents.remap_types(), wtxn)?; + index.put_documents_stats(wtxn, stats)?; + + Ok(true) + } + + fn target_version(&self) -> (u32, u32, u32) { + (1, 13, 1) + } +} + +#[allow(non_camel_case_types)] +pub(super) struct V1_13_1_To_Current(); + +impl UpgradeIndex for V1_13_1_To_Current { fn upgrade( &self, _wtxn: &mut RwTxn,