Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions entity/src/product_status.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::status::Status;
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
Expand All @@ -7,7 +8,7 @@ pub struct Model {
pub id: Uuid,
pub advisory_id: Uuid,
pub vulnerability_id: String,
pub status_id: Uuid,
pub status: Status,
pub package: Option<String>,
pub product_version_range_id: Uuid,
pub context_cpe_id: Option<Uuid>,
Expand All @@ -34,12 +35,6 @@ pub enum Relation {
)]
Advisory,

#[sea_orm(belongs_to = "super::status::Entity",
from = "Column::StatusId"
to = "super::status::Column::Id"
)]
Status,

#[sea_orm(belongs_to = "super::advisory_vulnerability::Entity",
from = "(Column::AdvisoryId, Column::VulnerabilityId)"
to = "(super::advisory_vulnerability::Column::AdvisoryId, super::advisory_vulnerability::Column::VulnerabilityId)"
Expand Down Expand Up @@ -77,12 +72,6 @@ impl Related<super::advisory::Entity> for Entity {
}
}

impl Related<super::status::Entity> for Entity {
fn to() -> RelationDef {
Relation::Status.def()
}
}

impl Related<super::advisory_vulnerability::Entity> for Entity {
fn to() -> RelationDef {
Relation::AdvisoryVulnerability.def()
Expand Down
15 changes: 2 additions & 13 deletions entity/src/purl_status.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::status::Status;
use sea_orm::LinkDef;
use sea_orm::entity::prelude::*;

Expand All @@ -8,7 +9,7 @@ pub struct Model {
pub id: Uuid,
pub advisory_id: Uuid,
pub vulnerability_id: String,
pub status_id: Uuid,
pub status: Status,
pub base_purl_id: Uuid,
pub version_range_id: Uuid,
pub context_cpe_id: Option<Uuid>,
Expand Down Expand Up @@ -43,12 +44,6 @@ pub enum Relation {
)]
Advisory,

#[sea_orm(belongs_to = "super::status::Entity",
from = "Column::StatusId"
to = "super::status::Column::Id"
)]
Status,

#[sea_orm(belongs_to = "super::advisory_vulnerability::Entity",
from = "(Column::AdvisoryId, Column::VulnerabilityId)"
to = "(super::advisory_vulnerability::Column::AdvisoryId, super::advisory_vulnerability::Column::VulnerabilityId)"
Expand Down Expand Up @@ -106,12 +101,6 @@ impl Related<super::advisory::Entity> for Entity {
}
}

impl Related<super::status::Entity> for Entity {
fn to() -> RelationDef {
Relation::Status.def()
}
}

impl Related<super::advisory_vulnerability::Entity> for Entity {
fn to() -> RelationDef {
Relation::AdvisoryVulnerability.def()
Expand Down
66 changes: 41 additions & 25 deletions entity/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
use crate::purl_status;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "status")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: Uuid,
pub slug: String,
pub name: String,
pub description: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::purl_status::Entity")]
PackageStatus,
}

impl Related<purl_status::Entity> for Entity {
fn to() -> RelationDef {
Relation::PackageStatus.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
use utoipa::ToSchema;

#[derive(
Copy,
Expand All @@ -33,16 +9,56 @@ impl ActiveModelBehavior for ActiveModel {}
Hash,
Debug,
PartialEq,
EnumIter,
DeriveActiveEnum,
strum::EnumString,
strum::Display,
Serialize,
Deserialize,
ToSchema,
)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "status")]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some test to ensure that the values of SeoORM align with the values or strum and serde.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[sdlc-workflow/verify-pr] Classified as code change request — sub-task TC-4508 created to address this feedback.

pub enum Status {
#[sea_orm(string_value = "affected")]
Affected,
#[sea_orm(string_value = "fixed")]
Fixed,
#[sea_orm(string_value = "not_affected")]
NotAffected,
#[sea_orm(string_value = "under_investigation")]
UnderInvestigation,
#[sea_orm(string_value = "recommended")]
Recommended,
}

#[cfg(test)]
mod tests {
use super::*;
use sea_orm::{ActiveEnum, Iterable};

/// Verifies that SeaORM, strum, and serde serialization values align for all Status variants.
#[test]
fn status_serialization_alignment() {
for variant in Status::iter() {
let sea_orm_value = variant.to_value();
let strum_value = variant.to_string();
let serde_value = serde_json::to_value(variant).unwrap();

assert_eq!(
sea_orm_value, strum_value,
"SeaORM and strum disagree for {:?}: sea_orm={}, strum={}",
variant, sea_orm_value, strum_value
);
assert_eq!(
serde_value.as_str().unwrap(),
strum_value,
"serde and strum disagree for {:?}: serde={}, strum={}",
variant,
serde_value,
strum_value
);
}
}
}
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ mod m0002160_fix_ref_fk;
mod m0002170_drop_cvss_tables;
mod m0002180_advisory_fk_indexes;
mod m0002190_vulnerability_base_score_advisory;
mod m0002200_replace_status_with_enum;

pub trait MigratorExt: Send {
fn build_migrations() -> Migrations;
Expand Down Expand Up @@ -132,6 +133,7 @@ impl MigratorExt for Migrator {
.normal(m0002170_drop_cvss_tables::Migration)
.normal(m0002180_advisory_fk_indexes::Migration)
.normal(m0002190_vulnerability_base_score_advisory::Migration)
.normal(m0002200_replace_status_with_enum::Migration)
}
}

Expand Down
Loading
Loading