mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 22:41:13 +00:00
feat: candidate fk on parent
This commit is contained in:
parent
12d25c9ffc
commit
c238b8ec45
9 changed files with 76 additions and 14 deletions
|
|
@ -225,14 +225,15 @@ mod tests {
|
|||
|
||||
let secret_message = "trnka".to_string();
|
||||
|
||||
Mutation::create_parent(&db, 1)
|
||||
.await.unwrap();
|
||||
|
||||
|
||||
let candidate = CandidateService::create(&db, 103151, &plain_text_password, "".to_string())
|
||||
.await
|
||||
.ok()
|
||||
.unwrap();
|
||||
|
||||
Mutation::create_parent(&db, 103151)
|
||||
.await.unwrap();
|
||||
|
||||
let encrypted_message =
|
||||
crypto::encrypt_password_with_recipients(&secret_message, &vec![&candidate.public_key])
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "admin")]
|
||||
pub struct Model {
|
||||
#[sea_orm(column_type = "Integer", primary_key)]
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub public_key: String,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
|
|
@ -28,10 +30,18 @@ pub struct Model {
|
|||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::parent::Entity")]
|
||||
Parent,
|
||||
#[sea_orm(has_many = "super::session::Entity")]
|
||||
Session,
|
||||
}
|
||||
|
||||
impl Related<super::parent::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Parent.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::session::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Session.def()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod admin;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
|
|
@ -14,6 +16,21 @@ pub struct Model {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::candidate::Entity",
|
||||
from = "Column::Application",
|
||||
to = "super::candidate::Column::Application",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Candidate,
|
||||
}
|
||||
|
||||
impl Related<super::candidate::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Candidate.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
|
||||
|
||||
pub use super::admin::Entity as Admin;
|
||||
pub use super::candidate::Entity as Candidate;
|
||||
pub use super::parent::Entity as Parent;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
|
|
@ -5,10 +7,8 @@ use sea_orm::entity::prelude::*;
|
|||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
#[sea_orm(column_type = "Integer", nullable)]
|
||||
pub admin_id: Option<i32>,
|
||||
#[sea_orm(column_type = "Integer", nullable)]
|
||||
pub user_id: Option<i32>,
|
||||
pub admin_id: Option<i32>,
|
||||
pub ip_address: String,
|
||||
pub created_at: DateTime,
|
||||
pub expires_at: DateTime,
|
||||
|
|
@ -34,16 +34,16 @@ pub enum Relation {
|
|||
Candidate,
|
||||
}
|
||||
|
||||
impl Related<super::candidate::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Candidate.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::admin::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Admin.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::candidate::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Candidate.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ mod m20221024_134454_insert_sample_admin;
|
|||
mod m20221025_154422_create_session;
|
||||
mod m20221027_194728_session_create_user_fk;
|
||||
mod m20221028_194728_session_create_admin_fk;
|
||||
mod m20221112_112212_create_parent_candidate_fk;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
|
@ -20,6 +21,7 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(m20221025_154422_create_session::Migration),
|
||||
Box::new(m20221027_194728_session_create_user_fk::Migration),
|
||||
Box::new(m20221028_194728_session_create_admin_fk::Migration),
|
||||
Box::new(m20221112_112212_create_parent_candidate_fk::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
26
migration/src/m20221112_112212_create_parent_candidate_fk.rs
Normal file
26
migration/src/m20221112_112212_create_parent_candidate_fk.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use crate::{m20221024_124701_create_parent::Parent, m20221024_121621_create_candidate::Candidate};
|
||||
|
||||
#[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("candidate_fk")
|
||||
.from(Parent::Table, Parent::Application)
|
||||
.to(Candidate::Table, Candidate::Application)
|
||||
.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("candidate_fk")
|
||||
.table(Parent::Table)
|
||||
.to_owned()).await
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue