migration/
m20240930_000017_logs_create_log.rs1use 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
13 .create_table(
14 Table::create()
15 .table(LogStatus::Table)
16 .if_not_exists()
17 .primary_key(
18 Index::create()
19 .name("pk_log_status")
20 .table(LogStatus::Table)
21 .col(LogStatus::BlockNumber)
22 .col(LogStatus::TransactionIndex)
23 .col(LogStatus::LogIndex),
24 )
25 .col(ColumnDef::new(LogStatus::TransactionIndex).not_null().binary_len(8))
26 .col(ColumnDef::new(LogStatus::LogIndex).not_null().binary_len(8))
27 .col(ColumnDef::new(LogStatus::BlockNumber).not_null().binary_len(8))
28 .col(ColumnDef::new(LogStatus::Processed).boolean().not_null().default(false))
29 .col(ColumnDef::new(LogStatus::ProcessedAt).date_time())
30 .col(ColumnDef::new(LogStatus::Checksum).binary_len(32))
31 .to_owned(),
32 )
33 .await?;
34
35 manager
36 .create_table(
37 Table::create()
38 .table(Log::Table)
39 .if_not_exists()
40 .primary_key(
41 Index::create()
42 .name("pk_log")
43 .table(Log::Table)
44 .col(Log::BlockNumber)
45 .col(Log::TransactionIndex)
46 .col(Log::LogIndex),
47 )
48 .col(ColumnDef::new(Log::TransactionIndex).not_null().binary_len(8))
49 .col(ColumnDef::new(Log::LogIndex).not_null().binary_len(8))
50 .col(ColumnDef::new(Log::BlockNumber).not_null().binary_len(8))
51 .col(ColumnDef::new(Log::BlockHash).binary_len(32).not_null())
52 .col(ColumnDef::new(Log::TransactionHash).binary_len(32).not_null())
53 .col(ColumnDef::new(Log::Address).binary_len(20).not_null())
54 .col(ColumnDef::new(Log::Topics).binary().not_null())
55 .col(ColumnDef::new(Log::Data).binary().not_null())
56 .col(ColumnDef::new(Log::Removed).boolean().not_null().default(false))
57 .foreign_key(
58 ForeignKey::create()
59 .name("fk_log_status_log")
60 .from(Log::Table, (Log::BlockNumber, Log::TransactionIndex, Log::LogIndex))
61 .to(
62 LogStatus::Table,
63 (LogStatus::BlockNumber, LogStatus::TransactionIndex, LogStatus::LogIndex),
64 )
65 .on_delete(ForeignKeyAction::Cascade)
66 .on_update(ForeignKeyAction::Cascade),
67 )
68 .to_owned(),
69 )
70 .await
71 }
72
73 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
74 manager.drop_table(Table::drop().table(Log::Table).to_owned()).await?;
75 manager
76 .drop_table(Table::drop().table(LogStatus::Table).to_owned())
77 .await
78 }
79}
80
81#[allow(clippy::enum_variant_names)]
82#[derive(DeriveIden)]
83enum Log {
84 Table,
85 Address,
87 Topics,
90 Data,
92 BlockNumber,
94 TransactionHash,
97 TransactionIndex,
99 BlockHash,
101 LogIndex,
103 Removed,
105}
106
107#[derive(DeriveIden)]
108enum LogStatus {
109 Table,
110 BlockNumber,
112 TransactionIndex,
113 LogIndex,
114 Processed,
116 ProcessedAt,
118 Checksum,
120}