feat: upload new packages to queue
This commit is contained in:
parent
f9518d6b7d
commit
fa6de9b035
6 changed files with 110 additions and 54 deletions
|
|
@ -4,6 +4,8 @@ use chrono::NaiveDateTime;
|
|||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::db::PackageState;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "package")]
|
||||
pub struct Model {
|
||||
|
|
@ -24,6 +26,7 @@ pub struct Model {
|
|||
pub pgp_sig_size: Option<i64>,
|
||||
pub sha256_sum: String,
|
||||
pub compression: String,
|
||||
pub state: PackageState,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
|
|
|||
|
|
@ -81,7 +81,12 @@ impl MigrationTrait for Migration {
|
|||
.col(ColumnDef::new(Package::PgpSig).string_len(255))
|
||||
.col(ColumnDef::new(Package::PgpSigSize).big_integer())
|
||||
.col(ColumnDef::new(Package::Sha256Sum).char_len(64).not_null())
|
||||
.col(ColumnDef::new(Package::Compression).string_len(16).not_null())
|
||||
.col(
|
||||
ColumnDef::new(Package::Compression)
|
||||
.string_len(16)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(Package::State).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-package-repo_id")
|
||||
|
|
@ -264,6 +269,7 @@ pub enum Package {
|
|||
PgpSigSize,
|
||||
Sha256Sum,
|
||||
Compression,
|
||||
State,
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
|
|
|
|||
|
|
@ -30,6 +30,17 @@ pub enum PackageRelatedEnum {
|
|||
Optdepend,
|
||||
}
|
||||
|
||||
#[derive(EnumIter, DeriveActiveEnum, Deserialize, Serialize, PartialEq, Eq, Clone, Debug)]
|
||||
#[sea_orm(rs_type = "i32", db_type = "Integer")]
|
||||
pub enum PackageState {
|
||||
#[sea_orm(num_value = 0)]
|
||||
PendingCommit,
|
||||
#[sea_orm(num_value = 1)]
|
||||
Committed,
|
||||
#[sea_orm(num_value = 2)]
|
||||
PendingDeletion,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct FullPackage {
|
||||
#[serde(flatten)]
|
||||
|
|
|
|||
|
|
@ -68,9 +68,17 @@ pub async fn delete_with_arch(conn: &DbConn, repo_id: i32, arch: &str) -> Result
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Package) -> Result<()> {
|
||||
pub async fn insert(
|
||||
conn: &DbConn,
|
||||
repo_id: i32,
|
||||
pkg: crate::repo::package::Package,
|
||||
) -> Result<package::Model> {
|
||||
let info = pkg.info;
|
||||
|
||||
// Doing this manually is not the recommended way, but the generic error type of the
|
||||
// transaction function didn't play well with my current error handling
|
||||
let txn = conn.begin().await?;
|
||||
|
||||
let model = package::ActiveModel {
|
||||
id: NotSet,
|
||||
repo_id: Set(repo_id),
|
||||
|
|
@ -88,9 +96,10 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack
|
|||
pgp_sig_size: Set(info.pgpsigsize),
|
||||
sha256_sum: Set(info.sha256sum),
|
||||
compression: Set(pkg.compression.extension().unwrap().to_string()),
|
||||
state: Set(PackageState::PendingCommit),
|
||||
};
|
||||
|
||||
let pkg_entry = model.insert(conn).await?;
|
||||
let pkg_entry = model.insert(&txn).await?;
|
||||
|
||||
// Insert all the related tables
|
||||
PackageLicense::insert_many(info.licenses.iter().map(|s| package_license::ActiveModel {
|
||||
|
|
@ -98,7 +107,7 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack
|
|||
name: Set(s.to_string()),
|
||||
}))
|
||||
.on_empty_do_nothing()
|
||||
.exec(conn)
|
||||
.exec(&txn)
|
||||
.await?;
|
||||
|
||||
PackageGroup::insert_many(info.groups.iter().map(|s| package_group::ActiveModel {
|
||||
|
|
@ -106,7 +115,7 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack
|
|||
name: Set(s.to_string()),
|
||||
}))
|
||||
.on_empty_do_nothing()
|
||||
.exec(conn)
|
||||
.exec(&txn)
|
||||
.await?;
|
||||
|
||||
let related = info
|
||||
|
|
@ -146,7 +155,7 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack
|
|||
name: Set(s.to_string()),
|
||||
}))
|
||||
.on_empty_do_nothing()
|
||||
.exec(conn)
|
||||
.exec(&txn)
|
||||
.await?;
|
||||
|
||||
PackageFile::insert_many(pkg.files.iter().map(|s| package_file::ActiveModel {
|
||||
|
|
@ -154,10 +163,12 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack
|
|||
path: Set(s.display().to_string()),
|
||||
}))
|
||||
.on_empty_do_nothing()
|
||||
.exec(conn)
|
||||
.exec(&txn)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
txn.commit().await?;
|
||||
|
||||
Ok(pkg_entry)
|
||||
}
|
||||
|
||||
pub async fn full(conn: &DbConn, id: i32) -> Result<Option<FullPackage>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue