-
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
88fa55c
commit 4feb467
Showing
3 changed files
with
153 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
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(VersionedPurl::Table) | ||
.name(Indexes::VersionedPurlBasePurlIdIDX.to_string()) | ||
.col(VersionedPurl::BasePurlId) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.table(PurlStatus::Table) | ||
.name(Indexes::PurlStatusBasePurlIdIDX.to_string()) | ||
.col(PurlStatus::BasePurlId) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.table(Status::Table) | ||
.name(Indexes::StatusSlugPartialIDX.to_string()) | ||
.col(Status::Slug) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.table(SbomPackagePurlRef::Table) | ||
.name(Indexes::SbomPackagePurlRefSbomIdIDX.to_string()) | ||
.col(SbomPackagePurlRef::SbomId) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.table(SbomPackagePurlRef::Table) | ||
.name(Indexes::SbomPackagePurlRefNodeIdIDX.to_string()) | ||
.col(SbomPackagePurlRef::NodeId) | ||
.to_owned(), | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(SbomPackagePurlRef::Table) | ||
.name(Indexes::SbomPackagePurlRefNodeIdIDX.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(SbomPackagePurlRef::Table) | ||
.name(Indexes::SbomPackagePurlRefSbomIdIDX.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(Status::Table) | ||
.name(Indexes::StatusSlugPartialIDX.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(PurlStatus::Table) | ||
.name(Indexes::PurlStatusBasePurlIdIDX.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.if_exists() | ||
.table(VersionedPurl::Table) | ||
.name(Indexes::VersionedPurlBasePurlIdIDX.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[allow(clippy::enum_variant_names)] | ||
#[derive(DeriveIden)] | ||
enum Indexes { | ||
VersionedPurlBasePurlIdIDX, | ||
PurlStatusBasePurlIdIDX, | ||
StatusSlugPartialIDX, | ||
SbomPackagePurlRefSbomIdIDX, | ||
SbomPackagePurlRefNodeIdIDX, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum VersionedPurl { | ||
Table, | ||
BasePurlId, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum PurlStatus { | ||
Table, | ||
BasePurlId, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Status { | ||
Table, | ||
Slug, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum SbomPackagePurlRef { | ||
Table, | ||
SbomId, | ||
NodeId, | ||
} |
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