-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b70b91
commit 103cfe5
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use deepsize::DeepSizeOf; | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] | ||
#[sea_orm(table_name = "sbom_external_package_node")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub sbom_id: Uuid, | ||
#[sea_orm(primary_key)] | ||
pub node_id: String, | ||
|
||
pub external_node_id: String, | ||
|
||
pub external_node_type: ExternalPackageType, | ||
|
||
pub target_sbom_id: Option<Uuid>, | ||
|
||
} | ||
|
||
#[sea_orm(rs_type = "i32", db_type = "Integer")] | ||
#[serde(rename_all = "snake_case")] | ||
#[derive(DeepSizeOf)] | ||
pub enum ExternalPackageType { | ||
#[sea_orm(num_value = 0)] | ||
SPDX, | ||
#[sea_orm(num_value = 1)] | ||
CDX, | ||
#[sea_orm(num_value = 2)] | ||
RH_PRODUCT_COMPONENT, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::sbom::Entity", | ||
from = "Column::SbomId", | ||
to = "super::sbom::Column::SbomId" | ||
)] | ||
Sbom, | ||
#[sea_orm( | ||
belongs_to = "super::package_relates_to_package::Entity", | ||
from = "Column::SbomId", | ||
to = "super::package_relates_to_package::Column::SbomId", | ||
on_condition = r#"super::package_relates_to_package::Column::Relationship.eq(crate::relationship::Relationship::Describes)"# | ||
)] | ||
DescribesSbom, | ||
} | ||
|
||
impl Related<super::sbom::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Sbom.def() | ||
} | ||
} | ||
|
||
impl Related<super::package_relates_to_package::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::DescribesSbom.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
migration/src/m0000880_create_sbom_external_package_node.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
pub(crate) const _EXTERNAL_NODE_TYPE_ENUM: [(i32, &str); 3] = | ||
[(0, "SPDX"), (1, "CDX"), (2, "RH_PRODUCT_COMPONENT")]; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(SbomExternalPackageNode::Table) | ||
.col( | ||
ColumnDef::new(SbomExternalPackageNode::SbomId) | ||
.uuid() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(SbomExternalPackageNode::NodeId) | ||
.string() | ||
.not_null(), | ||
) | ||
.primary_key( | ||
Index::create() | ||
.col(SbomExternalPackageNode::SbomId) | ||
.col(SbomExternalPackageNode::NodeId), | ||
) | ||
.col( | ||
ColumnDef::new(SbomExternalPackageNode::ExternalNodeId) | ||
.string() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(SbomExternalPackageNode::ExternalNodeType) | ||
.integer() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(SbomExternalPackageNode::TargetSbomId).uuid()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table( | ||
Table::drop() | ||
.table(SbomExternalPackageNode::Table) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum SbomExternalPackageNode { | ||
Table, | ||
SbomId, | ||
NodeId, | ||
ExternalNodeId, | ||
ExternalNodeType, | ||
TargetSbomId, | ||
} |