Skip to content

Commit

Permalink
remove old relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
JimFuller-RedHat committed Jan 30, 2025
1 parent 19cca70 commit 439911a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 68 deletions.
56 changes: 14 additions & 42 deletions entity/src/relationship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,36 @@ use std::fmt;
// When adding a new variant, also add this to the "relationship" table.
pub enum Relationship {
#[sea_orm(num_value = 0)]
ContainedBy,
Contains,
#[sea_orm(num_value = 1)]
DependencyOf,
Dependency,
#[sea_orm(num_value = 2)]
DevDependencyOf,
DevDependency,
#[sea_orm(num_value = 3)]
OptionalDependencyOf,
OptionalDependency,
#[sea_orm(num_value = 4)]
ProvidedDependencyOf,
ProvidedDependency,
#[sea_orm(num_value = 5)]
TestDependencyOf,
TestDependency,
#[sea_orm(num_value = 6)]
RuntimeDependencyOf,
RuntimeDependency,
#[sea_orm(num_value = 7)]
ExampleOf,
Example,
#[sea_orm(num_value = 8)]
GeneratedFrom,
Generates,
#[sea_orm(num_value = 9)]
AncestorOf,
#[sea_orm(num_value = 10)]
VariantOf,
Variant,
#[sea_orm(num_value = 11)]
BuildToolOf,
BuildTool,
#[sea_orm(num_value = 12)]
DevToolOf,
DevTool,
#[sea_orm(num_value = 13)]
DescribedBy,
Describes,
#[sea_orm(num_value = 14)]
PackageOf,
Package,
#[sea_orm(num_value = 15)]
Contains,
#[sea_orm(num_value = 16)]
Dependency,
#[sea_orm(num_value = 17)]
DevDependency,
#[sea_orm(num_value = 18)]
OptionalDependency,
#[sea_orm(num_value = 19)]
ProvidedDependency,
#[sea_orm(num_value = 20)]
TestDependency,
#[sea_orm(num_value = 21)]
RuntimeDependency,
#[sea_orm(num_value = 22)]
Example,
#[sea_orm(num_value = 23)]
Generates,
#[sea_orm(num_value = 24)]
Variant,
#[sea_orm(num_value = 25)]
BuildTool,
#[sea_orm(num_value = 26)]
DevTool,
#[sea_orm(num_value = 27)]
Describes,
#[sea_orm(num_value = 28)]
Packages,
#[sea_orm(num_value = 29)]
Undefined,
}

Expand Down
28 changes: 14 additions & 14 deletions migration/src/m0000860_normalise_relationships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
const DATA: [(i32, &str); 14] = [
(16, "Contains"),
(17, "Dependency"),
(18, "DevDependency"),
(19, "OptionalDependency"),
(20, "ProvidedDependency"),
(21, "TestDependency"),
(22, "RuntimeDependency"),
(23, "Example"),
(24, "Generates"),
(25, "Variant"),
(26, "BuildTool"),
(27, "DevTool"),
(28, "Describes"),
(29, "Packages"),
(0, "Contains"),
(1, "Dependency"),
(2, "DevDependency"),
(3, "OptionalDependency"),
(4, "ProvidedDependency"),
(5, "TestDependency"),
(6, "RuntimeDependency"),
(7, "Example"),
(8, "Generates"),
(10, "Variant"),
(11, "BuildTool"),
(12, "DevTool"),
(13, "Describes"),
(14, "Packages"),
];

#[async_trait::async_trait]
Expand Down
2 changes: 1 addition & 1 deletion modules/analysis/src/service/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl AnalysisService {
nodes.get(&edge.left_node_id),
nodes.get(&edge.right_node_id),
) {
if edge.relationship == Relationship::DescribedBy {
if edge.relationship == Relationship::Describes {
describedby_node_id.push(*left);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/fundamental/src/sbom/service/sbom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl SbomService {
paginated,
Which::Right,
SbomNodeReference::All,
Some(Relationship::DescribedBy),
Some(Relationship::Describes), // TODO: Is this right ?
db,
)
.await
Expand Down
4 changes: 2 additions & 2 deletions modules/fundamental/tests/sbom/spdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn parse_spdx_quarkus(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
let contains = service
.related_packages(
sbom.sbom.sbom_id,
Relationship::ContainedBy,
Relationship::Contains, // TODO: Is this right ?
first,
&ctx.db,
)
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn test_parse_spdx(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
Default::default(),
Which::Right,
first,
Some(Relationship::ContainedBy),
Some(Relationship::Contains), //TODO: Is this right ?
&ctx.db,
)
.await?
Expand Down
7 changes: 4 additions & 3 deletions modules/ingestor/src/graph/sbom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl SbomContext {
fn query_describes_packages(&self) -> Select<sbom_package::Entity> {
sbom_package::Entity::find()
.filter(sbom::Column::SbomId.eq(self.sbom.sbom_id))
.filter(package_relates_to_package::Column::Relationship.eq(Relationship::DescribedBy))
.filter(package_relates_to_package::Column::Relationship.eq(Relationship::Describes))
.select_only()
.join(JoinType::Join, sbom_package::Relation::Sbom.def())
.join(JoinType::Join, sbom_package::Relation::Node.def())
Expand Down Expand Up @@ -663,7 +663,7 @@ impl SbomContext {
) -> anyhow::Result<()> {
self.ingest_package_relates_to_package(
RelationshipReference::Root,
Relationship::DescribedBy,
Relationship::Describes,
RelationshipReference::Purl(package),
connection,
)
Expand All @@ -678,8 +678,9 @@ impl SbomContext {
connection: &C,
) -> anyhow::Result<()> {
self.ingest_package_relates_to_package(
// TODO: Is this right ?
RelationshipReference::Root,
Relationship::DescribedBy,
Relationship::Describes,
RelationshipReference::Cpe(cpe),
connection,
)
Expand Down
11 changes: 6 additions & 5 deletions modules/ingestor/src/graph/sbom/spdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ impl SbomContext {

for described in sbom_data.document_creation_information.document_describes {
relationships.relate(
described,
Relationship::DescribedBy,
// TODO: Is this right ?
sbom_data
.document_creation_information
.spdx_identifier
.clone(),
Relationship::Describes,
described,
);
product_packages.push(
sbom_data
Expand All @@ -96,8 +97,8 @@ impl SbomContext {

relationships.relate(left.to_string(), rel, right.to_string());

if rel == Relationship::DescribedBy {
product_packages.push(left.to_string());
if rel == Relationship::Describes {
product_packages.push(right.to_string()); // TODO: Is this right ?
}
}

Expand Down Expand Up @@ -267,7 +268,7 @@ impl<'spdx> TryFrom<(&'spdx str, &'spdx RelationshipType, &'spdx str)> for SpdxR
RelationshipType::OptionalDependencyOf => {
Ok((right, Relationship::OptionalDependency, left))
}
RelationshipType::PackageOf => Ok((right, Relationship::Packages, left)),
RelationshipType::PackageOf => Ok((right, Relationship::Package, left)),
RelationshipType::ProvidedDependencyOf => {
Ok((right, Relationship::ProvidedDependency, left))
}
Expand Down

0 comments on commit 439911a

Please sign in to comment.