-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break
description_en
into another table with a lang
key to be mor…
…e flexible. Test the aforementioned.
- Loading branch information
1 parent
1e45efe
commit 6e7bfd1
Showing
8 changed files
with
168 additions
and
23 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
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,29 @@ | ||
use crate::vulnerability; | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] | ||
#[sea_orm(table_name = "vulnerability_description")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub vulnerability_id: i32, | ||
pub lang: String, | ||
pub description: String, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::vulnerability::Entity", | ||
from = "super::vulnerability_description::Column::VulnerabilityId" | ||
to = "super::vulnerability::Column::Id")] | ||
Vulnerability, | ||
} | ||
|
||
impl Related<vulnerability::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Vulnerability.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
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
77 changes: 77 additions & 0 deletions
77
migration/src/m0000012_create_vulnerability_description.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,77 @@ | ||
use crate::m0000011_create_vulnerability::Vulnerability; | ||
use crate::m0000032_create_advisory_vulnerability::AdvisoryVulnerability; | ||
use sea_orm_migration::prelude::*; | ||
|
||
use crate::Now; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
// Replace the sample below with your own migration scripts | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(VulnerabilityDescription::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(VulnerabilityDescription::Id) | ||
.integer() | ||
.not_null() | ||
.auto_increment() | ||
.primary_key(), | ||
) | ||
.col( | ||
ColumnDef::new(AdvisoryVulnerability::VulnerabilityId) | ||
.integer() | ||
.not_null(), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.from_col(VulnerabilityDescription::VulnerabilityId) | ||
.to(Vulnerability::Table, Vulnerability::Id) | ||
.on_delete(ForeignKeyAction::Cascade), | ||
) | ||
.col( | ||
ColumnDef::new(VulnerabilityDescription::Timestamp) | ||
.timestamp_with_time_zone() | ||
.default(Func::cust(Now)), | ||
) | ||
.col( | ||
ColumnDef::new(VulnerabilityDescription::Lang) | ||
.string() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(VulnerabilityDescription::Description) | ||
.string() | ||
.not_null(), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table( | ||
Table::drop() | ||
.table(VulnerabilityDescription::Table) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
pub enum VulnerabilityDescription { | ||
Table, | ||
Id, | ||
Timestamp, | ||
// -- | ||
VulnerabilityId, | ||
Lang, | ||
Description, | ||
} |