Skip to main content

migration/
m20251124_00002_tickets_create_outgoing_ticket_index.rs

1use sea_orm_migration::prelude::*;
2
3#[derive(DeriveMigrationName)]
4pub struct Migration;
5
6#[async_trait::async_trait]
7impl MigrationTrait for Migration {
8    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9        manager
10            .create_table(
11                Table::create()
12                    .table(OutgoingTicketIndex::Table)
13                    .if_not_exists()
14                    .col(
15                        ColumnDef::new(OutgoingTicketIndex::Id)
16                            .integer()
17                            .not_null()
18                            .auto_increment()
19                            .primary_key(),
20                    )
21                    .col(
22                        ColumnDef::new(OutgoingTicketIndex::ChannelId)
23                            .string_len(64)
24                            .not_null()
25                            .unique_key(),
26                    )
27                    .col(ColumnDef::new(OutgoingTicketIndex::Epoch).integer().not_null())
28                    .col(
29                        ColumnDef::new(OutgoingTicketIndex::Index)
30                            .not_null()
31                            .binary_len(8)
32                            .default(vec![0u8; 8]),
33                    )
34                    .to_owned(),
35            )
36            .await?;
37
38        manager
39            .create_index(
40                Index::create()
41                    .name("idx_channel_id_epoch")
42                    .table(OutgoingTicketIndex::Table)
43                    .col(OutgoingTicketIndex::ChannelId)
44                    .col(OutgoingTicketIndex::Epoch)
45                    .to_owned(),
46            )
47            .await
48    }
49
50    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
51        manager
52            .drop_index(Index::drop().name("idx_channel_id_epoch").to_owned())
53            .await?;
54
55        manager
56            .drop_table(Table::drop().table(OutgoingTicketIndex::Table).to_owned())
57            .await
58    }
59}
60
61#[derive(DeriveIden)]
62enum OutgoingTicketIndex {
63    Table,
64    Id,
65    ChannelId,
66    Epoch,
67    Index,
68}