Portfolio/migration/src/m20221027_194728_session_create_user_fk.rs
2023-01-14 14:24:13 +01:00

26 lines
No EOL
890 B
Rust

use sea_orm_migration::prelude::*;
use crate::{m20221025_154422_create_session::Session, m20230114_114628_create_application::Application};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.create_foreign_key(ForeignKey::create()
.name("user_fk")
.from(Session::Table, Session::CandidateId)
.to(Application::Table, Application::Id)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade)
.to_owned()).await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.drop_foreign_key(ForeignKey::drop()
.name("user_fk")
.table(Session::Table)
.to_owned()).await
}
}