migration/
m20240226_000004_index_create_node_info.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(NodeInfo::Table)
13                    .if_not_exists()
14                    .col(
15                        ColumnDef::new(NodeInfo::Id)
16                            .integer()
17                            .not_null()
18                            .auto_increment()
19                            .primary_key(),
20                    )
21                    .col(
22                        ColumnDef::new(NodeInfo::SafeBalance)
23                            .binary_len(12)
24                            .not_null()
25                            .default(vec![0u8; 12]),
26                    )
27                    .col(
28                        ColumnDef::new(NodeInfo::SafeAllowance)
29                            .binary_len(12)
30                            .not_null()
31                            .default(vec![0u8; 12]),
32                    )
33                    .col(ColumnDef::new(NodeInfo::SafeAddress).string_len(40).null())
34                    .col(ColumnDef::new(NodeInfo::ModuleAddress).string_len(40).null())
35                    .to_owned(),
36            )
37            .await
38    }
39
40    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
41        manager
42            .drop_table(Table::drop().table(NodeInfo::Table).to_owned())
43            .await
44    }
45}
46
47#[derive(DeriveIden)]
48enum NodeInfo {
49    Table,
50    Id,
51    SafeBalance,
52    SafeAllowance,
53    SafeAddress,
54    ModuleAddress,
55}