From 365f7ccaaa8635655171e4d6eaf02f80e66f4c6e Mon Sep 17 00:00:00 2001 From: Michael Ferris Date: Thu, 19 Sep 2024 19:52:14 -0400 Subject: [PATCH] fix: breakout subnetwork indexes into separate migration --- migration/src/lib.rs | 2 + .../src/m20240814_121507_census_subnetwork.rs | 24 +------- ...20240919_121611_census_subnetwork_index.rs | 56 +++++++++++++++++++ 3 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 migration/src/m20240919_121611_census_subnetwork_index.rs diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 3764e8ad..4734c90a 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -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; @@ -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), ] } } diff --git a/migration/src/m20240814_121507_census_subnetwork.rs b/migration/src/m20240814_121507_census_subnetwork.rs index 98d2ca76..3cbb3ed1 100644 --- a/migration/src/m20240814_121507_census_subnetwork.rs +++ b/migration/src/m20240814_121507_census_subnetwork.rs @@ -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> { @@ -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) @@ -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 } diff --git a/migration/src/m20240919_121611_census_subnetwork_index.rs b/migration/src/m20240919_121611_census_subnetwork_index.rs new file mode 100644 index 00000000..1ec1300e --- /dev/null +++ b/migration/src/m20240919_121611_census_subnetwork_index.rs @@ -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, +}