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> {
|
|
|
|
manager
|
|
|
|
.create_table(
|
|
|
|
Table::create()
|
|
|
|
.table(Admin::Table)
|
|
|
|
.col(
|
|
|
|
ColumnDef::new(Admin::Id)
|
|
|
|
.big_unsigned()
|
|
|
|
.not_null()
|
|
|
|
.auto_increment()
|
|
|
|
.primary_key(),
|
|
|
|
)
|
|
|
|
.col(
|
2023-04-05 22:19:03 +03:00
|
|
|
ColumnDef::new(Admin::UserId)
|
2023-02-19 23:27:53 +03:00
|
|
|
.big_unsigned()
|
|
|
|
.unique_key()
|
2023-04-05 22:19:03 +03:00
|
|
|
.not_null(),
|
2023-02-19 23:27:53 +03:00
|
|
|
)
|
|
|
|
.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> {
|
|
|
|
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,
|
2023-04-05 22:19:03 +03:00
|
|
|
Id,
|
2023-02-19 23:27:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Iden)]
|
|
|
|
enum Admin {
|
|
|
|
Table,
|
|
|
|
Id,
|
|
|
|
UserId,
|
|
|
|
}
|