From c42a52e863544c75054c7c678eb6551d722577ce Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Mon, 24 Oct 2022 12:30:06 +0200 Subject: [PATCH] chore: candidate migrace --- .../src/m20221024_121621_create_candidate.rs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 migration/src/m20221024_121621_create_candidate.rs diff --git a/migration/src/m20221024_121621_create_candidate.rs b/migration/src/m20221024_121621_create_candidate.rs new file mode 100644 index 0000000..c32b99f --- /dev/null +++ b/migration/src/m20221024_121621_create_candidate.rs @@ -0,0 +1,73 @@ +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(Candidate::Table) + .if_not_exists() + .col( + ColumnDef::new(Candidate::Application) + .integer() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(Candidate::Code).string().not_null()) + .col(ColumnDef::new(Candidate::Name).string()) + .col(ColumnDef::new(Candidate::Surname).string()) + .col(ColumnDef::new(Candidate::BirthSurname).string()) + .col(ColumnDef::new(Candidate::Birthplace).string()) + .col(ColumnDef::new(Candidate::Birthdate).date()) + .col(ColumnDef::new(Candidate::Address).string()) + .col(ColumnDef::new(Candidate::Telephone).string()) + .col(ColumnDef::new(Candidate::Citizenship).string()) + .col(ColumnDef::new(Candidate::Email).string()) + .col(ColumnDef::new(Candidate::Sex).string()) + .col(ColumnDef::new(Candidate::Study).string()) + .col(ColumnDef::new(Candidate::PersonalIdentificationNumber).string()) + .col(ColumnDef::new(Candidate::PersonalIdentificationNumberHash).text()) + .col(ColumnDef::new(Candidate::PublicKey).string().not_null()) + .col(ColumnDef::new(Candidate::PrivateKey).string().not_null()) + .col(ColumnDef::new(Candidate::CreatedAt).date_time().not_null()) + .col(ColumnDef::new(Candidate::UpdatedAt).date_time().not_null()) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Candidate::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Candidate { + Table, + Application, + Code, + Name, + Surname, + BirthSurname, + Birthplace, + Birthdate, + Address, + Telephone, + Citizenship, + Email, + Sex, + Study, + PersonalIdentificationNumber, + PersonalIdentificationNumberHash, + PublicKey, + PrivateKey, + CreatedAt, + UpdatedAt, +}