migration/
m20250219_000020_logs_add_index.rs

1use sea_orm_migration::prelude::*;
2
3#[derive(DeriveMigrationName)]
4pub struct Migration;
5
6const IDX_NAME: &str = "idx_log_status_block_number_processed";
7
8#[async_trait::async_trait]
9impl MigrationTrait for Migration {
10    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
11        manager
12            .create_index(
13                sea_query::Index::create()
14                    .if_not_exists()
15                    .name(IDX_NAME)
16                    .table(LogStatus::Table)
17                    .col((LogStatus::BlockNumber, IndexOrder::Asc))
18                    .col(LogStatus::Processed)
19                    .to_owned(),
20            )
21            .await
22    }
23
24    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
25        manager.drop_index(Index::drop().name(IDX_NAME).to_owned()).await
26    }
27}
28
29#[derive(DeriveIden)]
30enum LogStatus {
31    Table,
32    BlockNumber,
33    Processed,
34}