From 3fb5a51cfb1214a7a31e6ce4f65108c14a625551 Mon Sep 17 00:00:00 2001 From: EETagent Date: Mon, 24 Oct 2022 12:53:58 +0200 Subject: [PATCH] chore: parent migrace --- entity/src/lib.rs | 1 + entity/src/parent.rs | 23 +++++++++ entity/src/prelude.rs | 1 + migration/src/lib.rs | 7 ++- .../src/m20221024_124701_create_parent.rs | 49 +++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 entity/src/parent.rs create mode 100644 migration/src/m20221024_124701_create_parent.rs diff --git a/entity/src/lib.rs b/entity/src/lib.rs index fe0475a..ffaaadc 100644 --- a/entity/src/lib.rs +++ b/entity/src/lib.rs @@ -5,3 +5,4 @@ pub mod prelude; pub mod admin; pub mod candidate; +pub mod parent; diff --git a/entity/src/parent.rs b/entity/src/parent.rs new file mode 100644 index 0000000..48e1f7c --- /dev/null +++ b/entity/src/parent.rs @@ -0,0 +1,23 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0 +use sea_orm::entity::prelude::*; +use chrono::{DateTime, Local}; +use rocket::serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[serde(crate = "rocket::serde")] +#[sea_orm(table_name = "parent")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub application: i32, + pub name: Option, + pub surname: Option, + pub telephone: Option, + pub email: Option, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/prelude.rs b/entity/src/prelude.rs index a755023..eba3b7f 100644 --- a/entity/src/prelude.rs +++ b/entity/src/prelude.rs @@ -1,2 +1,3 @@ pub use super::admin::Entity as Admin; pub use super::candidate::Entity as Candidate; +pub use super::parent::Entity as Parent; diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 0c472c3..934224e 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -2,12 +2,17 @@ pub use sea_orm_migration::prelude::*; mod m20221024_111310_create_admin; mod m20221024_121621_create_candidate; +mod m20221024_124701_create_parent; pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![Box::new(m20221024_111310_create_admin::Migration), Box::new(m20221024_121621_create_candidate::Migration)] + vec![ + Box::new(m20221024_111310_create_admin::Migration), + Box::new(m20221024_121621_create_candidate::Migration), + Box::new(m20221024_124701_create_parent::Migration), + ] } } diff --git a/migration/src/m20221024_124701_create_parent.rs b/migration/src/m20221024_124701_create_parent.rs new file mode 100644 index 0000000..721e1c1 --- /dev/null +++ b/migration/src/m20221024_124701_create_parent.rs @@ -0,0 +1,49 @@ +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(Parent::Table) + .if_not_exists() + .col( + ColumnDef::new(Parent::Application) + .integer() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(Parent::Name).string()) + .col(ColumnDef::new(Parent::Surname).string()) + .col(ColumnDef::new(Parent::Telephone).string()) + .col(ColumnDef::new(Parent::Email).string()) + .col(ColumnDef::new(Parent::CreatedAt).date_time().not_null()) + .col(ColumnDef::new(Parent::UpdatedAt).date_time().not_null()) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Parent::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Parent { + Table, + Application, + Name, + Surname, + Telephone, + Email, + CreatedAt, + UpdatedAt, +}