Skip to content

Commit

Permalink
fix: breakout subnetwork indexes into separate migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrferris committed Sep 20, 2024
1 parent 0485b74 commit 365f7cc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod m20240322_205213_add_content_audit_index;
mod m20240515_064320_state_roots;
mod m20240720_111606_create_census_index;
mod m20240814_121507_census_subnetwork;
mod m20240919_121611_census_subnetwork_index;

pub struct Migrator;

Expand All @@ -35,6 +36,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240515_064320_state_roots::Migration),
Box::new(m20240720_111606_create_census_index::Migration),
Box::new(m20240814_121507_census_subnetwork::Migration),
Box::new(m20240919_121611_census_subnetwork_index::Migration),
]
}
}
24 changes: 2 additions & 22 deletions migration/src/m20240814_121507_census_subnetwork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ 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> {
Expand All @@ -19,16 +16,8 @@ impl MigrationTrait for Migration {
.to_owned(),
)
.await;
let _ = manager
.create_index(
Index::create()
.name(INDEX_CENSUS_SUBNET_INDEX)
.table(Census::Table)
.col(Census::SubNetwork)
.to_owned(),
)
.await;
let _ = manager

manager
.alter_table(
Table::alter()
.table(CensusNode::Table)
Expand All @@ -37,15 +26,6 @@ impl MigrationTrait for Migration {
)
.to_owned(),
)
.await;
manager
.create_index(
Index::create()
.name(INDEX_CENSUS_NODE_SUBNET_INDEX)
.table(CensusNode::Table)
.col(CensusNode::SubNetwork)
.to_owned(),
)
.await
}

Expand Down
56 changes: 56 additions & 0 deletions migration/src/m20240919_121611_census_subnetwork_index.rs
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,
}

0 comments on commit 365f7cc

Please sign in to comment.