Skip to content

Commit

Permalink
add missing index for token_accounts table (metaplex-foundation#243)
Browse files Browse the repository at this point in the history
* add missing index for asset and token_accounts table
  • Loading branch information
Nagaprasadvr authored Feb 15, 2025
1 parent 8537c93 commit 1b19650
Show file tree
Hide file tree
Showing 2 changed files with 37 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 @@ -45,6 +45,7 @@ mod m20240320_120101_add_mpl_core_info_items;
mod m20240520_120101_add_mpl_core_external_plugins_columns;
mod m20240718_161232_change_supply_columns_to_numeric;
mod m20241119_060310_add_token_inscription_enum_variant;
mod m20250213_053451_add_idx_token_accounts_owner;

pub mod model;

Expand Down Expand Up @@ -99,6 +100,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240520_120101_add_mpl_core_external_plugins_columns::Migration),
Box::new(m20240718_161232_change_supply_columns_to_numeric::Migration),
Box::new(m20241119_060310_add_token_inscription_enum_variant::Migration),
Box::new(m20250213_053451_add_idx_token_accounts_owner::Migration),
]
}
}
35 changes: 35 additions & 0 deletions migration/src/m20250213_053451_add_idx_token_accounts_owner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::model::table::TokenAccounts;
use sea_orm::{ConnectionTrait, DatabaseBackend, Statement};
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let conn = manager.get_connection();

conn.execute(Statement::from_string(
DatabaseBackend::Postgres,
"CREATE INDEX CONCURRENTLY IF NOT EXISTS token_accounts_owner_idx ON token_accounts (owner);"
.to_string(),
))
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(
Index::drop()
.name("token_accounts_owner_idx")
.table(TokenAccounts::Table)
.to_owned(),
)
.await?;

Ok(())
}
}

0 comments on commit 1b19650

Please sign in to comment.