hoprd_migration/
m20240814_000001_metadata_create_db.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(Aliases::Table)
13                    .if_not_exists()
14                    .col(
15                        ColumnDef::new(Aliases::Id)
16                            .integer()
17                            .not_null()
18                            .auto_increment()
19                            .primary_key(),
20                    )
21                    .col(ColumnDef::new(Aliases::Alias).string().not_null().unique_key())
22                    .col(ColumnDef::new(Aliases::PeerId).string().not_null().unique_key())
23                    .to_owned(),
24            )
25            .await
26    }
27
28    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
29        manager.drop_table(Table::drop().table(Aliases::Table).to_owned()).await
30    }
31}
32
33#[derive(DeriveIden)]
34enum Aliases {
35    Table,
36    Id,
37    Alias,
38    PeerId,
39}