-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: breakout subnetwork indexes into separate migration
- Loading branch information
Showing
3 changed files
with
60 additions
and
22 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,56 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
const INDEX_CENSUS_SUBNET_INDEX: &str = "idx_census_subnet"; | ||
const INDEX_CENSUS_NODE_SUBNET_INDEX: &str = "idx_census_node_subnet"; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let _ = manager | ||
.create_index( | ||
Index::create() | ||
.name(INDEX_CENSUS_SUBNET_INDEX) | ||
.table(Census::Table) | ||
.col(Census::SubNetwork) | ||
.to_owned(), | ||
) | ||
.await; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.name(INDEX_CENSUS_NODE_SUBNET_INDEX) | ||
.table(CensusNode::Table) | ||
.col(CensusNode::SubNetwork) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let _ = manager | ||
.drop_index(Index::drop().name(INDEX_CENSUS_SUBNET_INDEX).to_owned()) | ||
.await; | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.name(INDEX_CENSUS_NODE_SUBNET_INDEX) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(Iden)] | ||
enum Census { | ||
Table, | ||
SubNetwork, | ||
} | ||
|
||
#[derive(Iden)] | ||
enum CensusNode { | ||
Table, | ||
SubNetwork, | ||
} |