Skip to content

Commit

Permalink
chore - add indexes to assist sorting at scale (fixes trustification#645
Browse files Browse the repository at this point in the history
).
  • Loading branch information
JimFuller-RedHat authored and ctron committed Aug 7, 2024
1 parent 31ece32 commit f51ff0e
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mod m0000490_cascade_advisory_delete;
mod m0000500_fix_sbom_node_fks;
mod m0000501_perf_indexes;
mod m0000510_create_maven_cmp_fns;
mod m0000520_scale_indexes;

pub struct Migrator;

Expand Down Expand Up @@ -128,6 +129,7 @@ impl MigratorTrait for Migrator {
Box::new(m0000500_fix_sbom_node_fks::Migration),
Box::new(m0000501_perf_indexes::Migration),
Box::new(m0000510_create_maven_cmp_fns::Migration),
Box::new(m0000520_scale_indexes::Migration),
]
}
}
Expand Down
113 changes: 113 additions & 0 deletions migration/src/m0000520_scale_indexes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
#[allow(deprecated)]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_index(
Index::create()
.table(Cvss3::Table)
.name(Indexes::Cvss3VulnIdIdx.to_string())
.col(Cvss3::VulnerabilityId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(Cvss3::Table)
.name(Indexes::Cvss3AdvIdIdx.to_string())
.col(Cvss3::AdvisoryId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(Cvss4::Table)
.name(Indexes::Cvss4VulnIdIdx.to_string())
.col(Cvss4::VulnerabilityId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(Cvss4::Table)
.name(Indexes::Cvss4AdvIdIdx.to_string())
.col(Cvss4::AdvisoryId)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(
Index::drop()
.if_exists()
.table(Cvss4::Table)
.name(Indexes::Cvss4AdvIdIdx.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(Cvss4::Table)
.name(Indexes::Cvss4VulnIdIdx.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(Cvss3::Table)
.name(Indexes::Cvss3AdvIdIdx.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(Cvss3::Table)
.name(Indexes::Cvss3VulnIdIdx.to_string())
.to_owned(),
)
.await?;

Ok(())
}
}

#[allow(clippy::enum_variant_names)]
#[derive(DeriveIden)]
pub enum Indexes {
Cvss3VulnIdIdx,
Cvss3AdvIdIdx,
Cvss4VulnIdIdx,
Cvss4AdvIdIdx,
}

#[derive(DeriveIden)]
pub enum Cvss3 {
Table,
AdvisoryId,
VulnerabilityId,
}

#[derive(DeriveIden)]
pub enum Cvss4 {
Table,
AdvisoryId,
VulnerabilityId,
}

0 comments on commit f51ff0e

Please sign in to comment.