Skip to content

Commit 6960f51

Browse files
committed
add composite index
1 parent 1b6e50b commit 6960f51

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

crates/database/migration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod m20250411_072004_add_l2_block;
88
mod m20250616_223947_add_metadata;
99
mod m20250904_175949_block_signature;
1010
mod m20251028_110719_add_l1_block_table;
11+
mod m20251125_181536_add_batch_commit_index;
1112

1213
mod migration_info;
1314
pub use migration_info::{
@@ -28,6 +29,7 @@ impl<MI: MigrationInfo + Send + Sync + 'static> MigratorTrait for Migrator<MI> {
2829
Box::new(m20250616_223947_add_metadata::Migration),
2930
Box::new(m20250904_175949_block_signature::Migration),
3031
Box::new(m20251028_110719_add_l1_block_table::Migration),
32+
Box::new(m20251125_181536_add_batch_commit_index::Migration),
3133
]
3234
}
3335
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use super::m20220101_000001_create_batch_commit_table::BatchCommit;
2+
use sea_orm_migration::prelude::*;
3+
4+
#[derive(DeriveMigrationName)]
5+
pub struct Migration;
6+
7+
#[async_trait::async_trait]
8+
impl MigrationTrait for Migration {
9+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
10+
// Add a composite index on (status, finalized_block_number, index) for the `batch_commit`
11+
// table.
12+
manager
13+
.create_index(
14+
Index::create()
15+
.name("idx_batch_commit_status_finalized_block_number_index")
16+
.col(BatchCommit::Status)
17+
.col(BatchCommit::FinalizedBlockNumber)
18+
.col(BatchCommit::Index)
19+
.table(BatchCommit::Table)
20+
.to_owned(),
21+
)
22+
.await
23+
}
24+
25+
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
26+
Ok(())
27+
}
28+
}

0 commit comments

Comments
 (0)