From 73fd622d6f250197ccaebaa2b7834df3a03bb146 Mon Sep 17 00:00:00 2001 From: Morty Date: Tue, 23 Sep 2025 22:01:55 +0800 Subject: [PATCH] feat(database): add index block_hash for table block_signature --- crates/database/migration/src/lib.rs | 2 + .../m20250923_135359_add_index_block_hash.rs | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 crates/database/migration/src/m20250923_135359_add_index_block_hash.rs diff --git a/crates/database/migration/src/lib.rs b/crates/database/migration/src/lib.rs index ddb5f1a7..5cadddb5 100644 --- a/crates/database/migration/src/lib.rs +++ b/crates/database/migration/src/lib.rs @@ -10,6 +10,7 @@ mod m20250825_093350_remove_unsafe_l2_blocks; mod m20250829_042803_add_table_indexes; mod m20250901_102341_add_commit_batch_processed_column; mod m20250904_175949_block_signature; +mod m20250923_135359_add_index_block_hash; mod migration_info; pub use migration_info::{ MigrationInfo, ScrollDevMigrationInfo, ScrollMainnetMigrationInfo, ScrollSepoliaMigrationInfo, @@ -31,6 +32,7 @@ impl MigratorTrait for Migrator { Box::new(m20250829_042803_add_table_indexes::Migration), Box::new(m20250901_102341_add_commit_batch_processed_column::Migration), Box::new(m20250904_175949_block_signature::Migration), + Box::new(m20250923_135359_add_index_block_hash::Migration), ] } } diff --git a/crates/database/migration/src/m20250923_135359_add_index_block_hash.rs b/crates/database/migration/src/m20250923_135359_add_index_block_hash.rs new file mode 100644 index 00000000..0ad6caf1 --- /dev/null +++ b/crates/database/migration/src/m20250923_135359_add_index_block_hash.rs @@ -0,0 +1,37 @@ +use super::m20250904_175949_block_signature::BlockSignature; +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> { + // Create indexes for the `block_signature` table. + manager + .create_index( + Index::create() + .name("idx_block_signature_block_hash") + .col(BlockSignature::BlockHash) + .table(BlockSignature::Table) + .to_owned(), + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Drop indexes for the `block_signature` table. + manager + .drop_index( + Index::drop() + .name("idx_block_signature_block_hash") + .table(BlockSignature::Table) + .to_owned(), + ) + .await?; + + Ok(()) + } +}