Skip to content

Commit

Permalink
create some perf indexes - note we may drop the ones we add to sbom_n…
Browse files Browse the repository at this point in the history
…ode and sbom_package as final db perf will adjust column statistics
  • Loading branch information
JimFuller-RedHat committed Feb 6, 2025
1 parent c2ff34e commit 8c8c367
Show file tree
Hide file tree
Showing 2 changed files with 140 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 @@ -106,6 +106,7 @@ mod m0000860_normalise_relationships;
mod m0000870_source_doc_indexes;
mod m0000880_org_name_index;
mod m0000890_create_sbom_external_node;
mod m0000900_perf_indexes;

#[cfg(feature = "ai")]
pub mod ai;
Expand Down Expand Up @@ -221,6 +222,7 @@ impl MigratorTrait for Migrator {
Box::new(m0000870_source_doc_indexes::Migration),
Box::new(m0000880_org_name_index::Migration),
Box::new(m0000890_create_sbom_external_node::Migration),
Box::new(m0000900_perf_indexes::Migration),
]
}
}
Expand Down
138 changes: 138 additions & 0 deletions migration/src/m0000900_perf_indexes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
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(PurlStatus::Table)
.name(Indexes::PurlStatusVulnIdIDX.to_string())
.col(PurlStatus::VulnerabilityId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(SbomPackage::Table)
.name(Indexes::SbomPackageSbomIdNodeIdIDX.to_string())
.col(SbomPackage::SbomId)
.col(SbomPackage::NodeId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(SbomPackage::Table)
.name(Indexes::SbomPackageSbomIdIDX.to_string())
.col(SbomPackage::SbomId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(SbomNode::Table)
.name(Indexes::SbomNodeSbomIdNodeIdIDX.to_string())
.col(SbomNode::SbomId)
.col(SbomNode::NodeId)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.table(SbomNode::Table)
.name(Indexes::SbomNodeSbomIdIDX.to_string())
.col(SbomNode::SbomId)
.to_owned(),
)
.await?;
Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(
Index::drop()
.if_exists()
.table(SbomNode::Table)
.name(Indexes::SbomNodeSbomIdIDX.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(SbomNode::Table)
.name(Indexes::SbomNodeSbomIdNodeIdIDX.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(SbomPackage::Table)
.name(Indexes::SbomPackageSbomIdIDX.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(SbomPackage::Table)
.name(Indexes::SbomPackageSbomIdNodeIdIDX.to_string())
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.if_exists()
.table(PurlStatus::Table)
.name(Indexes::PurlStatusVulnIdIDX.to_string())
.to_owned(),
)
.await?;
Ok(())
}
}

#[allow(clippy::enum_variant_names)]
#[derive(DeriveIden)]
enum Indexes {
PurlStatusVulnIdIDX,
SbomPackageSbomIdNodeIdIDX,
SbomPackageSbomIdIDX,
SbomNodeSbomIdNodeIdIDX,
SbomNodeSbomIdIDX,
}

#[derive(DeriveIden)]
enum PurlStatus {
Table,
VulnerabilityId,
}

#[derive(DeriveIden)]
enum SbomPackage {
Table,
SbomId,
NodeId,
}

#[derive(DeriveIden)]
enum SbomNode {
Table,
SbomId,
NodeId,
}

0 comments on commit 8c8c367

Please sign in to comment.