migration/
m20250107_000019_logs_meta_table.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(LogTopicInfo::Table)
13                    .if_not_exists()
14                    .col(
15                        ColumnDef::new(LogTopicInfo::Id)
16                            .primary_key()
17                            .not_null()
18                            .integer()
19                            .auto_increment(),
20                    )
21                    .col(ColumnDef::new(LogTopicInfo::Address).string_len(40).not_null())
22                    .col(ColumnDef::new(LogTopicInfo::Topic).string_len(64).not_null())
23                    .to_owned(),
24            )
25            .await?;
26
27        manager
28            .create_index(
29                Index::create()
30                    .if_not_exists()
31                    .name("idx_contract_log_topic")
32                    .table(LogTopicInfo::Table)
33                    .col(LogTopicInfo::Address)
34                    .col(LogTopicInfo::Topic)
35                    .unique()
36                    .to_owned(),
37            )
38            .await
39    }
40
41    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
42        manager
43            .drop_index(
44                Index::drop()
45                    .name("idx_contract_log_topic")
46                    .table(LogTopicInfo::Table)
47                    .to_owned(),
48            )
49            .await?;
50
51        manager
52            .drop_table(Table::drop().table(LogTopicInfo::Table).to_owned())
53            .await
54    }
55}
56
57#[derive(DeriveIden)]
58enum LogTopicInfo {
59    Table,
60    Id,
61    /// Contract address for filter
62    Address,
63    /// Topic for the contract on this address
64    Topic,
65}