Skip to content

Commit

Permalink
Fix parse old table and fix insert order
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Feb 13, 2025
1 parent 90ccf3d commit 1e9a8c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions oma-history/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub struct InstallHistoryEntry {
pub new_size: i64,
pub download_size: i64,
pub arch: String,
#[serde(rename = "op")]
pub operation: InstallOperation,
}

Expand Down
23 changes: 13 additions & 10 deletions oma-history/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oma_pm_operation_type::{InstallOperation, RemoveTag};
use rusqlite::Connection;
use serde::Deserialize;
use tracing::{info, warn};
use tracing::{debug, info, warn};

use crate::{
HistoryEntryInner, HistoryError, HistoryResult, InstallHistoryEntry, RemoveHistoryEntry,
Expand Down Expand Up @@ -43,7 +43,7 @@ struct OldTableEntry {
fn migration_from_oma_db_v2(conn: &Connection) -> HistoryResult<()> {
let table = get_old_table(conn)?;

for i in table {
for i in table.iter().rev() {
let command = match &i.summary_type {
OldSummaryType::Install(items) => format!("oma install {}", items.join(" ")),
OldSummaryType::Upgrade(items) => format!("oma upgrade {}", items.join(" ")),
Expand Down Expand Up @@ -102,39 +102,39 @@ fn migration_from_oma_db_v2(conn: &Connection) -> HistoryResult<()> {
)
.map_err(HistoryError::ExecuteError)?;

for i in i.inner.install {
for i in &i.inner.install {
let op: u8 = i.operation.into();
let op = op as i64;

conn.execute(
INSERT_INSTALL_TABLE,
(
id,
i.pkg_name,
i.old_version,
i.new_version,
&i.pkg_name,
&i.old_version,
&i.new_version,
i.old_size,
i.new_size,
i.download_size,
i.arch,
&i.arch,
op,
),
)
.map_err(HistoryError::ExecuteError)?;
}

for j in i.inner.remove {
for j in &i.inner.remove {
conn.execute(
INSERT_REMOVE_TABLE,
(id, &j.pkg_name, j.version, j.size, j.arch),
(id, &j.pkg_name, &j.version, j.size, &j.arch),
)
.map_err(HistoryError::ExecuteError)?;

conn.execute(
INSERT_REMOVE_DETAIL_TABLE,
(
id,
j.pkg_name,
&j.pkg_name,
if j.tags.contains(&RemoveTag::AutoRemove) {
1
} else {
Expand Down Expand Up @@ -213,6 +213,9 @@ fn get_old_table(conn: &Connection) -> Result<Vec<OldTableEntry>, HistoryError>
summary_type,
) = i.map_err(HistoryError::ExecuteError)?;

debug!("install pacakges: {}", install_packages);

Check warning on line 216 in oma-history/src/migrations.rs

View workflow job for this annotation

GitHub Actions / check-typo

"pacakges" should be "packages".
debug!("remove packages: {}", remove_packages);

let install_packages =
match serde_json::from_str::<Vec<InstallHistoryEntry>>(&install_packages) {
Ok(i) => i,
Expand Down

0 comments on commit 1e9a8c6

Please sign in to comment.