Skip to content

Commit

Permalink
fix several type incompatibilities in postgres + sqlite interop cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas-Heiligenbrunner committed Jul 27, 2024
1 parent 8b36a47 commit fc3d6e0
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 28 deletions.
28 changes: 21 additions & 7 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aurcache"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -16,12 +16,13 @@ tar = "0.4.41"

rocket = "0.5.1"
rocket_okapi = { features = ["swagger"], git = "https://github.com/beyera/okapi.git", branch = "beyera/update-rocket-0.5.1" }
sea-orm = { version = "1.0.0-rc.7", features = [ "sqlx-sqlite", "sqlx-postgres", "runtime-tokio-rustls", "macros" ] }
sea-orm = { version = "1.0.0-rc.7", features = [ "sqlx-sqlite", "sqlx-postgres", "runtime-tokio-rustls", "macros", "with-bigdecimal" ] }
sea-orm-migration = {version = "1.0.0-rc.7", features = ["sqlx-sqlite", "runtime-tokio-rustls"]}
serde = "1.0.203"
rust-embed = "8.4.0"
rocket_seek_stream = "0.2.6"
shiplift = "0.7.0"
bigdecimal = "0.4.5"

[[bin]]
name = "aurcache"
Expand Down
10 changes: 8 additions & 2 deletions backend/src/api/stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::db::builds;
use crate::db::prelude::{Builds, Packages};
use crate::utils::dir_size::dir_size;
use bigdecimal::ToPrimitive;

use rocket::response::status::NotFound;
use rocket::serde::json::Json;
Expand All @@ -9,6 +10,7 @@ use rocket::{get, State};

use crate::api::types::input::ListStats;
use rocket_okapi::openapi;
use sea_orm::prelude::BigDecimal;
use sea_orm::{ColumnTrait, QueryFilter};
use sea_orm::{DatabaseConnection, EntityTrait};
use sea_orm::{DbBackend, FromQueryResult, PaginatorTrait, Statement};
Expand Down Expand Up @@ -51,7 +53,7 @@ async fn get_stats(db: &DatabaseConnection) -> anyhow::Result<ListStats> {

#[derive(Debug, FromQueryResult)]
struct BuildTimeStruct {
avg_build_time: Option<f64>,
avg_build_time: Option<BigDecimal>,
}

let unique: BuildTimeStruct =
Expand All @@ -66,7 +68,11 @@ async fn get_stats(db: &DatabaseConnection) -> anyhow::Result<ListStats> {
.await?
.ok_or(anyhow::anyhow!("No Average build time"))?;

let avg_build_time: u32 = unique.avg_build_time.unwrap_or(0.0) as u32;
let avg_build_time = unique
.avg_build_time
.unwrap_or(BigDecimal::try_from(0.0)?)
.to_u32()
.unwrap();

// Count total packages
let total_packages: u32 = Packages::find().count(db).await?.try_into()?;
Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/types/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ListPackageModel {
pub id: i32,
pub name: String,
pub status: i32,
pub outofdate: bool,
pub outofdate: i32,
pub latest_version: Option<String>,
pub latest_aur_version: String,
}
Expand All @@ -29,8 +29,8 @@ pub struct ListBuildsModel {
pkg_name: String,
version: String,
status: i32,
start_time: Option<u32>,
end_time: Option<u32>,
start_time: Option<i64>,
end_time: Option<i64>,
}

#[derive(FromQueryResult, Deserialize, JsonSchema, Serialize)]
Expand Down
13 changes: 4 additions & 9 deletions backend/src/builder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) async fn cancel_build(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32,
.as_secs() as i64,
));
let _ = build.clone().update(&db).await;

Expand Down Expand Up @@ -86,7 +86,7 @@ pub(crate) async fn prepare_build(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32,
.as_secs() as i64,
));
_ = new_build.update(&db).await;
build_logger
Expand All @@ -102,7 +102,7 @@ pub(crate) async fn prepare_build(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32,
.as_secs() as i64,
));
let _ = new_build.update(&db).await;

Expand Down Expand Up @@ -272,12 +272,7 @@ async fn move_and_add_pkgs(
package_file.save(&txn).await?;

repo_add(archive_name.clone())?;
build_logger
.append(format!(
"Successfully added '{}' to the repo archive",
archive_name
))
.await?;
println!("Successfully added '{}' to the repo archive", archive_name);
}
txn.commit().await?;
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions backend/src/db/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct Model {
pub pkg_id: i32,
pub output: Option<String>,
pub status: Option<i32>,
pub start_time: Option<u32>,
pub end_time: Option<u32>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 1 addition & 1 deletion backend/src/package/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn package_add(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32,
.as_secs() as i64,
)),
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion backend/src/package/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub async fn package_update(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32,
.as_secs() as i64,
)),
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/models/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Package {
factory Package.fromJson(Map<String, dynamic> json) {
return Package(
id: json["id"] as int,
outofdate: json["outofdate"] as bool,
outofdate: json["outofdate"] as num != 0,
status: json["status"] as int,
name: json["name"] as String,
latest_version: json["latest_version"] as String,
Expand Down

0 comments on commit fc3d6e0

Please sign in to comment.