web3-proxy/migration/src/m20230117_191358_admin_table.rs

59 lines
1.6 KiB
Rust
Raw Normal View History

2023-02-19 23:27:53 +03:00
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager
.create_table(
Table::create()
.table(Admin::Table)
.col(
ColumnDef::new(Admin::Id)
.big_unsigned()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(Admin::UserId)
.big_unsigned()
.unique_key()
.not_null()
)
.foreign_key(
ForeignKey::create()
.name("fk-admin-user_id")
.from(Admin::Table, Admin::UserId)
.to(User::Table, User::Id),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager
.drop_table(Table::drop().table(Admin::Table).to_owned())
.await
}
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum User {
Table,
Id
}
#[derive(Iden)]
enum Admin {
Table,
Id,
UserId,
}