migration/
m20250219_000021_channels_add_index.rs

1use sea_orm_migration::prelude::*;
2
3#[derive(DeriveMigrationName)]
4pub struct Migration;
5
6const IDX_NAME_CLOSURE_TIME: &str = "idx_channel_closure_time";
7const IDX_NAME_CHANNEL_STATUS: &str = "idx_channel_status";
8
9#[async_trait::async_trait]
10impl MigrationTrait for Migration {
11    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
12        manager
13            .create_index(
14                sea_query::Index::create()
15                    .if_not_exists()
16                    .name(IDX_NAME_CLOSURE_TIME)
17                    .table(Channel::Table)
18                    .col((Channel::ClosureTime, IndexOrder::Asc))
19                    .to_owned(),
20            )
21            .await?;
22
23        manager
24            .create_index(
25                sea_query::Index::create()
26                    .if_not_exists()
27                    .name(IDX_NAME_CHANNEL_STATUS)
28                    .table(Channel::Table)
29                    .col((Channel::Status, IndexOrder::Asc))
30                    .to_owned(),
31            )
32            .await
33    }
34
35    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
36        manager
37            .drop_index(Index::drop().name(IDX_NAME_CLOSURE_TIME).to_owned())
38            .await?;
39
40        manager
41            .drop_index(Index::drop().name(IDX_NAME_CHANNEL_STATUS).to_owned())
42            .await
43    }
44}
45
46#[allow(clippy::enum_variant_names)]
47#[derive(DeriveIden)]
48enum Channel {
49    Table,
50    Status,
51    ClosureTime,
52}