-
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
a074606
commit c2ff34e
Showing
3 changed files
with
170 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,60 @@ | ||
use deepsize::DeepSizeOf; | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] | ||
#[sea_orm(table_name = "sbom_external_node")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub sbom_id: Uuid, | ||
#[sea_orm(primary_key)] | ||
pub node_id: String, | ||
pub external_doc_ref: String, | ||
pub external_node_ref: String, | ||
pub external_type: ExternalType, | ||
pub target_sbom_id: Option<Uuid>, | ||
|
||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
#[sea_orm(rs_type = "i32", db_type = "Integer")] | ||
#[serde(rename_all = "snake_case")] | ||
#[derive(DeepSizeOf)] | ||
pub enum ExternalType { | ||
#[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
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,108 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
pub(crate) const _EXTERNAL_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(SbomExternalNode::Table) | ||
.col(ColumnDef::new(SbomExternalNode::SbomId).uuid().not_null()) | ||
.col(ColumnDef::new(SbomExternalNode::NodeId).string().not_null()) | ||
.primary_key( | ||
Index::create() | ||
.col(SbomExternalNode::SbomId) | ||
.col(SbomExternalNode::NodeId), | ||
) | ||
.col( | ||
ColumnDef::new(SbomExternalNode::ExternalDocRef) | ||
.string() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(SbomExternalNode::ExternalNodeRef) | ||
.string() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(SbomExternalNode::ExternalType) | ||
.integer() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(SbomExternalNode::TargetSbomId).uuid()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.table(SbomExternalNode::Table) | ||
.name(Indexes::SbomExternalNodeExternalDocRefIdx.to_string()) | ||
.col(SbomExternalNode::ExternalType) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.table(SbomExternalNode::Table) | ||
.name(Indexes::SbomExternalNodeExternalNodeRefIdx.to_string()) | ||
.col(SbomExternalNode::ExternalDocRef) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(SbomExternalNode::Table) | ||
.name(Indexes::SbomExternalNodeExternalNodeRefIdx.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(SbomExternalNode::Table) | ||
.name(Indexes::SbomExternalNodeExternalDocRefIdx.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.drop_table(Table::drop().table(SbomExternalNode::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Indexes { | ||
SbomExternalNodeExternalDocRefIdx, | ||
SbomExternalNodeExternalNodeRefIdx, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum SbomExternalNode { | ||
Table, | ||
SbomId, | ||
NodeId, | ||
ExternalDocRef, | ||
ExternalNodeRef, | ||
ExternalType, | ||
TargetSbomId, | ||
} |