diff --git a/oma-history/src/migrations.rs b/oma-history/src/migrations.rs index 1b8beadf..0d098c11 100644 --- a/oma-history/src/migrations.rs +++ b/oma-history/src/migrations.rs @@ -26,7 +26,7 @@ pub fn create_and_maybe_migration_from_oma_db_v2(conn: &Connection) -> HistoryRe .map_err(HistoryError::ExecuteError)?; if old_db_count != 0 && new_db_count == 0 { - info!("Mirgration from old history table"); + info!("Migrating oma history database, this may take a few minutes ..."); migration_from_oma_db_v2(conn)?; } @@ -56,8 +56,8 @@ fn handle_packages_items(items: &[String]) -> String { fn migration_from_oma_db_v2(conn: &Connection) -> HistoryResult<()> { let table = get_old_table(conn)?; - for i in table.iter().rev() { - let command = match &i.summary_type { + for entry in table { + let command = match &entry.summary_type { OldSummaryType::Install(items) => { format!("oma install {}", handle_packages_items(items)) } @@ -87,39 +87,43 @@ fn migration_from_oma_db_v2(conn: &Connection) -> HistoryResult<()> { INSERT_NEW_MAIN_TABLE, ( command, - i.time, - i.inner.is_success, - i.inner.disk_size, - i.inner.total_download_size, - i.inner + entry.time, + entry.inner.is_success, + entry.inner.disk_size, + entry.inner.total_download_size, + entry + .inner .install .iter() .filter(|x| x.operation == InstallOperation::Install) .count(), - i.inner.remove.len(), - i.inner + entry.inner.remove.len(), + entry + .inner .install .iter() .filter(|x| x.operation == InstallOperation::Upgrade) .count(), - i.inner + entry + .inner .install .iter() .filter(|x| x.operation == InstallOperation::Downgrade) .count(), - i.inner + entry + .inner .install .iter() .filter(|x| x.operation == InstallOperation::ReInstall) .count(), - i.summary_type == OldSummaryType::FixBroken, - i.summary_type == OldSummaryType::Undo, + entry.summary_type == OldSummaryType::FixBroken, + entry.summary_type == OldSummaryType::Undo, ), |row| row.get(0), ) .map_err(HistoryError::ExecuteError)?; - for i in &i.inner.install { + for i in &entry.inner.install { let op: u8 = i.operation.into(); let op = op as i64; @@ -140,7 +144,7 @@ fn migration_from_oma_db_v2(conn: &Connection) -> HistoryResult<()> { .map_err(HistoryError::ExecuteError)?; } - for j in &i.inner.remove { + for j in &entry.inner.remove { conn.execute( INSERT_REMOVE_TABLE, (id, &j.pkg_name, &j.version, j.size, &j.arch), @@ -192,7 +196,7 @@ pub enum OldSummaryType { fn get_old_table(conn: &Connection) -> Result, HistoryError> { let mut stmt = conn - .prepare("SELECT id, time, install_packages, remove_packages, disk_size, total_download_size, is_success, typ FROM \"history_oma_1.2\" ORDER BY id DESC") + .prepare("SELECT id, time, install_packages, remove_packages, disk_size, total_download_size, is_success, typ FROM \"history_oma_1.2\" ORDER BY id ASC") .map_err(HistoryError::ExecuteError)?; let res_iter = stmt .query_map([], |row| {