From 9dc330da6a7dfc9c2d5aae90fd2feda9d0912054 Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Mon, 24 Oct 2022 13:52:43 +0200 Subject: [PATCH] chore: sample fill admin table --- migration/Cargo.toml | 2 ++ migration/src/lib.rs | 2 ++ migration/src/m20221024_134454_fill_admin.rs | 30 ++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 migration/src/m20221024_134454_fill_admin.rs diff --git a/migration/Cargo.toml b/migration/Cargo.toml index fdd77e4..5bc4b91 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -11,6 +11,8 @@ path = "src/lib.rs" [dependencies] rocket = { version = "0.5.0-rc.2" } async-std = { version = "^1", features = ["attributes", "tokio1"] } +chrono = "0.4.22" +portfolio-entity = { path = "../entity" } [dependencies.sea-orm-migration] version = "^0.10.0" diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 934224e..b003527 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -3,6 +3,7 @@ pub use sea_orm_migration::prelude::*; mod m20221024_111310_create_admin; mod m20221024_121621_create_candidate; mod m20221024_124701_create_parent; +mod m20221024_134454_fill_admin; pub struct Migrator; @@ -13,6 +14,7 @@ impl MigratorTrait for Migrator { Box::new(m20221024_111310_create_admin::Migration), Box::new(m20221024_121621_create_candidate::Migration), Box::new(m20221024_124701_create_parent::Migration), + Box::new(m20221024_134454_fill_admin::Migration), ] } } diff --git a/migration/src/m20221024_134454_fill_admin.rs b/migration/src/m20221024_134454_fill_admin.rs new file mode 100644 index 0000000..fbd6726 --- /dev/null +++ b/migration/src/m20221024_134454_fill_admin.rs @@ -0,0 +1,30 @@ +use chrono::Local; +use entity::admin; +use sea_orm_migration::{prelude::*, sea_orm::{Set, ActiveModelTrait}}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let db = manager.get_connection(); + admin::ActiveModel { + name: Set("Administrátor Pepa".to_owned()), + public_key: Set("lorem ipsum".to_owned()), + private_key_hash: Set("lorem ipsum".to_owned()), + password_hash: Set("lorem ipsum".to_owned()), + created_at: Set(Local::now().naive_local()), + updated_at: Set(Local::now().naive_local()), + ..Default::default() + } + .insert(db) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + todo!() + } +}