feat: simplify database scheme
ci/woodpecker/push/clippy Pipeline is pending Details
ci/woodpecker/push/lint Pipeline is pending Details
ci/woodpecker/push/build Pipeline failed Details
ci/woodpecker/push/docker unknown status Details

db-centric-repos
Jef Roosens 2024-05-18 14:20:05 +02:00
parent fcb3a18416
commit 9963cff724
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
15 changed files with 96 additions and 370 deletions

View File

@ -3,11 +3,8 @@
pub mod prelude;
pub mod package;
pub mod package_conflicts;
pub mod package_depends;
pub mod package_file;
pub mod package_group;
pub mod package_license;
pub mod package_provides;
pub mod package_replaces;
pub mod package_related;
pub mod repo;

View File

@ -17,7 +17,7 @@ pub struct Model {
pub c_size: i64,
pub description: Option<String>,
pub url: Option<String>,
pub build_date: DateTime,
pub build_date: String,
pub packager: Option<String>,
pub pgp_sig: Option<String>,
pub pgp_sig_size: Option<i64>,
@ -26,20 +26,14 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::package_conflicts::Entity")]
PackageConflicts,
#[sea_orm(has_many = "super::package_depends::Entity")]
PackageDepends,
#[sea_orm(has_many = "super::package_file::Entity")]
PackageFile,
#[sea_orm(has_many = "super::package_group::Entity")]
PackageGroup,
#[sea_orm(has_many = "super::package_license::Entity")]
PackageLicense,
#[sea_orm(has_many = "super::package_provides::Entity")]
PackageProvides,
#[sea_orm(has_many = "super::package_replaces::Entity")]
PackageReplaces,
#[sea_orm(has_many = "super::package_related::Entity")]
PackageRelated,
#[sea_orm(
belongs_to = "super::repo::Entity",
from = "Column::RepoId",
@ -50,18 +44,6 @@ pub enum Relation {
Repo,
}
impl Related<super::package_conflicts::Entity> for Entity {
fn to() -> RelationDef {
Relation::PackageConflicts.def()
}
}
impl Related<super::package_depends::Entity> for Entity {
fn to() -> RelationDef {
Relation::PackageDepends.def()
}
}
impl Related<super::package_file::Entity> for Entity {
fn to() -> RelationDef {
Relation::PackageFile.def()
@ -80,15 +62,9 @@ impl Related<super::package_license::Entity> for Entity {
}
}
impl Related<super::package_provides::Entity> for Entity {
impl Related<super::package_related::Entity> for Entity {
fn to() -> RelationDef {
Relation::PackageProvides.def()
}
}
impl Related<super::package_replaces::Entity> for Entity {
fn to() -> RelationDef {
Relation::PackageReplaces.def()
Relation::PackageRelated.def()
}
}

View File

@ -1,33 +0,0 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "package_conflicts")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub package_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::package::Entity",
from = "Column::PackageId",
to = "super::package::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Package,
}
impl Related<super::package::Entity> for Entity {
fn to() -> RelationDef {
Relation::Package.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub package_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
pub path: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub package_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub package_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -1,33 +0,0 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "package_provides")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub package_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::package::Entity",
from = "Column::PackageId",
to = "super::package::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Package,
}
impl Related<super::package::Entity> for Entity {
fn to() -> RelationDef {
Relation::Package.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -4,14 +4,14 @@ use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "package_depends")]
#[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::PackageDepend,
pub r#type: crate::db::PackageRelatedEnum,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -1,33 +0,0 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "package_replaces")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub package_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub value: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::package::Entity",
from = "Column::PackageId",
to = "super::package::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Package,
}
impl Related<super::package::Entity> for Entity {
fn to() -> RelationDef {
Relation::Package.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -1,11 +1,8 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
pub use super::package::Entity as Package;
pub use super::package_conflicts::Entity as PackageConflicts;
pub use super::package_depends::Entity as PackageDepends;
pub use super::package_file::Entity as PackageFile;
pub use super::package_group::Entity as PackageGroup;
pub use super::package_license::Entity as PackageLicense;
pub use super::package_provides::Entity as PackageProvides;
pub use super::package_replaces::Entity as PackageReplaces;
pub use super::package_related::Entity as PackageRelated;
pub use super::repo::Entity as Repo;

View File

@ -8,7 +8,6 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(unique)]
pub name: String,
pub description: Option<String>,
}

View File

@ -72,14 +72,14 @@ impl MigrationTrait for Migration {
.not_null(),
)
.col(
ColumnDef::new(PackageLicense::Value)
ColumnDef::new(PackageLicense::Name)
.string_len(255)
.not_null(),
)
.primary_key(
Index::create()
.col(PackageLicense::PackageId)
.col(PackageLicense::Value),
.col(PackageLicense::Name),
)
.foreign_key(
ForeignKey::create()
@ -97,14 +97,14 @@ impl MigrationTrait for Migration {
.table(PackageGroup::Table)
.col(ColumnDef::new(PackageGroup::PackageId).integer().not_null())
.col(
ColumnDef::new(PackageGroup::Value)
ColumnDef::new(PackageGroup::Name)
.string_len(255)
.not_null(),
)
.primary_key(
Index::create()
.col(PackageGroup::PackageId)
.col(PackageGroup::Value),
.col(PackageGroup::Name),
)
.foreign_key(
ForeignKey::create()
@ -119,119 +119,28 @@ impl MigrationTrait for Migration {
manager
.create_table(
Table::create()
.table(PackageReplaces::Table)
.table(PackageRelated::Table)
.col(
ColumnDef::new(PackageReplaces::PackageId)
ColumnDef::new(PackageRelated::PackageId)
.integer()
.not_null(),
)
.col(ColumnDef::new(PackageRelated::Type).integer().not_null())
.col(
ColumnDef::new(PackageReplaces::Value)
ColumnDef::new(PackageRelated::Name)
.string_len(255)
.not_null(),
)
.primary_key(
Index::create()
.col(PackageReplaces::PackageId)
.col(PackageReplaces::Value),
)
.foreign_key(
ForeignKey::create()
.name("fk-package_replaces-package_id")
.from(PackageReplaces::Table, PackageReplaces::PackageId)
.to(Package::Table, Package::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(PackageConflicts::Table)
.col(
ColumnDef::new(PackageConflicts::PackageId)
.integer()
.not_null(),
)
.col(
ColumnDef::new(PackageConflicts::Value)
.string_len(255)
.not_null(),
)
.primary_key(
Index::create()
.col(PackageConflicts::PackageId)
.col(PackageConflicts::Value),
)
.foreign_key(
ForeignKey::create()
.name("fk-package_conflicts-package_id")
.from(PackageConflicts::Table, PackageConflicts::PackageId)
.to(Package::Table, Package::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(PackageProvides::Table)
.col(
ColumnDef::new(PackageProvides::PackageId)
.integer()
.not_null(),
)
.col(
ColumnDef::new(PackageProvides::Value)
.string_len(255)
.not_null(),
)
.primary_key(
Index::create()
.col(PackageProvides::PackageId)
.col(PackageProvides::Value),
)
.foreign_key(
ForeignKey::create()
.name("fk-package_provides-package_id")
.from(PackageProvides::Table, PackageProvides::PackageId)
.to(Package::Table, Package::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(PackageDepends::Table)
.col(
ColumnDef::new(PackageDepends::PackageId)
.integer()
.not_null(),
)
.col(
ColumnDef::new(PackageDepends::Type)
.string_len(6)
.not_null(),
)
.col(
ColumnDef::new(PackageDepends::Value)
.string_len(255)
.not_null(),
)
.primary_key(
Index::create()
.col(PackageDepends::PackageId)
.col(PackageDepends::Type)
.col(PackageDepends::Value),
.col(PackageRelated::PackageId)
.col(PackageRelated::Type)
.col(PackageRelated::Name),
)
.foreign_key(
ForeignKey::create()
.name("fk-package_depends-package_id")
.from(PackageDepends::Table, PackageDepends::PackageId)
.from(PackageRelated::Table, PackageRelated::PackageId)
.to(Package::Table, Package::Id)
.on_delete(ForeignKeyAction::Cascade),
)
@ -243,15 +152,11 @@ impl MigrationTrait for Migration {
Table::create()
.table(PackageFile::Table)
.col(ColumnDef::new(PackageFile::PackageId).integer().not_null())
.col(
ColumnDef::new(PackageFile::Value)
.string_len(255)
.not_null(),
)
.col(ColumnDef::new(PackageFile::Path).string_len(255).not_null())
.primary_key(
Index::create()
.col(PackageFile::PackageId)
.col(PackageFile::Value),
.col(PackageFile::Path),
)
.foreign_key(
ForeignKey::create()
@ -276,16 +181,7 @@ impl MigrationTrait for Migration {
.drop_table(Table::drop().table(PackageGroup::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(PackageReplaces::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(PackageConflicts::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(PackageProvides::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(PackageDepends::Table).to_owned())
.drop_table(Table::drop().table(PackageRelated::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(PackageFile::Table).to_owned())
@ -331,48 +227,27 @@ pub enum Package {
pub enum PackageLicense {
Table,
PackageId,
Value,
Name,
}
#[derive(Iden)]
pub enum PackageGroup {
Table,
PackageId,
Value,
Name,
}
#[derive(Iden)]
pub enum PackageReplaces {
Table,
PackageId,
Value,
}
#[derive(Iden)]
pub enum PackageConflicts {
Table,
PackageId,
Value,
}
#[derive(Iden)]
pub enum PackageProvides {
Table,
PackageId,
Value,
}
#[derive(Iden)]
pub enum PackageDepends {
pub enum PackageRelated {
Table,
PackageId,
Type,
Value,
Name,
}
#[derive(Iden)]
pub enum PackageFile {
Table,
PackageId,
Value,
Path,
}

View File

@ -13,16 +13,22 @@ use migrator::Migrator;
type Result<T> = std::result::Result<T, sea_orm::DbErr>;
#[derive(EnumIter, DeriveActiveEnum, Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
#[sea_orm(rs_type = "String", db_type = "String(Some(6))")]
pub enum PackageDepend {
#[sea_orm(string_value = "depend")]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
pub enum PackageRelatedEnum {
#[sea_orm(num_value = 0)]
Conflicts,
#[sea_orm(num_value = 1)]
Replaces,
#[sea_orm(num_value = 2)]
Provides,
#[sea_orm(num_value = 3)]
Depend,
#[sea_orm(string_value = "make")]
Make,
#[sea_orm(string_value = "check")]
Check,
#[sea_orm(string_value = "opt")]
Opt,
#[sea_orm(num_value = 4)]
Makedepend,
#[sea_orm(num_value = 5)]
Checkdepend,
#[sea_orm(num_value = 6)]
Optdepend,
}
#[derive(Serialize)]
@ -31,9 +37,7 @@ pub struct FullPackage {
entry: package::Model,
licenses: Vec<String>,
groups: Vec<String>,
replaces: Vec<String>,
provides: Vec<String>,
depends: Vec<(PackageDepend, String)>,
related: Vec<(PackageRelatedEnum, String)>,
files: Vec<String>,
}

View File

@ -71,7 +71,7 @@ impl PackageQuery {
c_size: Set(info.csize),
description: Set(info.description),
url: Set(info.url),
build_date: Set(info.build_date),
build_date: Set(info.build_date.to_string()),
packager: Set(info.packager),
pgp_sig: Set(info.pgpsig),
pgp_sig_size: Set(info.pgpsigsize),
@ -83,7 +83,7 @@ impl PackageQuery {
// Insert all the related tables
PackageLicense::insert_many(info.licenses.iter().map(|s| package_license::ActiveModel {
package_id: Set(pkg_entry.id),
value: Set(s.to_string()),
name: Set(s.to_string()),
}))
.on_empty_do_nothing()
.exec(&self.conn)
@ -91,64 +91,57 @@ impl PackageQuery {
PackageGroup::insert_many(info.groups.iter().map(|s| package_group::ActiveModel {
package_id: Set(pkg_entry.id),
value: Set(s.to_string()),
name: Set(s.to_string()),
}))
.on_empty_do_nothing()
.exec(&self.conn)
.await?;
PackageReplaces::insert_many(info.replaces.iter().map(|s| package_replaces::ActiveModel {
let related = info
.conflicts
.iter()
.map(|s| (PackageRelatedEnum::Conflicts, s))
.chain(
info.replaces
.iter()
.map(|s| (PackageRelatedEnum::Replaces, s)),
)
.chain(
info.provides
.iter()
.map(|s| (PackageRelatedEnum::Provides, s)),
)
.chain(info.depends.iter().map(|s| (PackageRelatedEnum::Depend, s)))
.chain(
info.makedepends
.iter()
.map(|s| (PackageRelatedEnum::Depend, s)),
)
.chain(
info.checkdepends
.iter()
.map(|s| (PackageRelatedEnum::Checkdepend, s)),
)
.chain(
info.optdepends
.iter()
.map(|s| (PackageRelatedEnum::Optdepend, s)),
);
PackageRelated::insert_many(related.map(|(t, s)| package_related::ActiveModel {
package_id: Set(pkg_entry.id),
value: Set(s.to_string()),
}))
.on_empty_do_nothing()
.exec(&self.conn)
.await?;
PackageConflicts::insert_many(info.conflicts.iter().map(|s| {
package_conflicts::ActiveModel {
package_id: Set(pkg_entry.id),
value: Set(s.to_string()),
}
}))
.on_empty_do_nothing()
.exec(&self.conn)
.await?;
PackageProvides::insert_many(info.provides.iter().map(|s| package_provides::ActiveModel {
package_id: Set(pkg_entry.id),
value: Set(s.to_string()),
}))
.on_empty_do_nothing()
.exec(&self.conn)
.await?;
r#type: Set(t),
name: Set(s.to_string()),
}));
PackageFile::insert_many(pkg.files.iter().map(|s| package_file::ActiveModel {
package_id: Set(pkg_entry.id),
value: Set(s.display().to_string()),
path: Set(s.display().to_string()),
}))
.on_empty_do_nothing()
.exec(&self.conn)
.await?;
let deps = info
.depends
.iter()
.map(|d| (PackageDepend::Depend, d))
.chain(info.makedepends.iter().map(|d| (PackageDepend::Make, d)))
.chain(info.checkdepends.iter().map(|d| (PackageDepend::Check, d)))
.chain(info.optdepends.iter().map(|d| (PackageDepend::Opt, d)))
.map(|(t, s)| package_depends::ActiveModel {
package_id: Set(pkg_entry.id),
r#type: Set(t),
value: Set(s.to_string()),
});
PackageDepends::insert_many(deps)
.on_empty_do_nothing()
.exec(&self.conn)
.await?;
Ok(())
}
@ -159,51 +152,35 @@ impl PackageQuery {
.all(&self.conn)
.await?
.into_iter()
.map(|e| e.value)
.map(|e| e.name)
.collect();
let groups = entry
.find_related(PackageGroup)
.all(&self.conn)
.await?
.into_iter()
.map(|e| e.value)
.map(|e| e.name)
.collect();
let replaces = entry
.find_related(PackageReplaces)
let related = entry
.find_related(PackageRelated)
.all(&self.conn)
.await?
.into_iter()
.map(|e| e.value)
.collect();
let provides = entry
.find_related(PackageProvides)
.all(&self.conn)
.await?
.into_iter()
.map(|e| e.value)
.collect();
let depends = entry
.find_related(PackageDepends)
.all(&self.conn)
.await?
.into_iter()
.map(|e| (e.r#type, e.value))
.map(|e| (e.r#type, e.name))
.collect();
let files = entry
.find_related(PackageFile)
.all(&self.conn)
.await?
.into_iter()
.map(|e| e.value)
.map(|e| e.path)
.collect();
Ok(Some(FullPackage {
entry,
licenses,
groups,
replaces,
provides,
depends,
related,
files,
}))
} else {

View File

@ -281,7 +281,7 @@ impl From<Package> for package::ActiveModel {
c_size: Set(info.csize),
description: Set(info.description),
url: Set(info.url),
build_date: Set(info.build_date),
build_date: Set(info.build_date.to_string()),
packager: Set(info.packager),
pgp_sig: Set(info.pgpsig),
pgp_sig_size: Set(info.pgpsigsize),