feat: start of better repo manager
This commit is contained in:
parent
421f6ae69b
commit
cc2dc9b28f
8 changed files with 85 additions and 22 deletions
|
|
@ -22,6 +22,7 @@ pub struct Model {
|
|||
pub pgp_sig: Option<String>,
|
||||
pub pgp_sig_size: Option<i64>,
|
||||
pub sha256_sum: String,
|
||||
pub compression: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
|
|
|||
|
|
@ -3,13 +3,15 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::db::PackageRelatedEnum;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "package_related")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub package_id: i32,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub r#type: crate::db::PackageRelatedEnum,
|
||||
pub r#type: PackageRelatedEnum,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub name: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ 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).char_len(16).not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-package-repo_id")
|
||||
|
|
@ -221,6 +222,7 @@ pub enum Package {
|
|||
PgpSig,
|
||||
PgpSigSize,
|
||||
Sha256Sum,
|
||||
Compression,
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
|
|
|
|||
|
|
@ -45,20 +45,15 @@ pub async fn by_id(conn: &DbConn, id: i32) -> Result<Option<package::Model>> {
|
|||
pub async fn by_fields(
|
||||
conn: &DbConn,
|
||||
repo_id: i32,
|
||||
name: &str,
|
||||
version: Option<&str>,
|
||||
arch: &str,
|
||||
name: &str,
|
||||
) -> Result<Option<package::Model>> {
|
||||
let mut query = Package::find()
|
||||
Package::find()
|
||||
.filter(package::Column::RepoId.eq(repo_id))
|
||||
.filter(package::Column::Name.eq(name))
|
||||
.filter(package::Column::Arch.eq(arch));
|
||||
|
||||
if let Some(version) = version {
|
||||
query = query.filter(package::Column::Version.eq(version));
|
||||
}
|
||||
|
||||
query.one(conn).await
|
||||
.filter(package::Column::Arch.eq(arch))
|
||||
.one(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_with_arch(conn: &DbConn, repo_id: i32, arch: &str) -> Result<DeleteResult> {
|
||||
|
|
@ -88,6 +83,7 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack
|
|||
pgp_sig: Set(info.pgpsig),
|
||||
pgp_sig_size: Set(info.pgpsigsize),
|
||||
sha256_sum: Set(info.sha256sum),
|
||||
compression: Set(pkg.compression.extension().unwrap().to_string())
|
||||
};
|
||||
|
||||
let pkg_entry = model.insert(conn).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue