refactor: down pro vytvoření admin účtu

This commit is contained in:
EETagent 2022-10-24 16:53:07 +02:00
parent dd8f0b0f72
commit f797950e00
2 changed files with 34 additions and 15 deletions

View file

@ -14,7 +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),
Box::new(m20221024_134454_fill_admin::Migration::default()),
]
}
}

View file

@ -1,30 +1,49 @@
use chrono::Local;
use entity::admin;
use sea_orm_migration::{prelude::*, sea_orm::{Set, ActiveModelTrait}};
use sea_orm_migration::{
prelude::*,
sea_orm::{ActiveModelTrait, Set},
};
#[derive(DeriveMigrationName)]
pub struct Migration;
pub struct Migration {
admin: admin::ActiveModel,
}
impl Default for Migration {
fn default() -> Self {
Self {
admin: admin::ActiveModel {
id: Set(1),
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()
},
}
}
}
#[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?;
self.admin.to_owned().insert(db).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
todo!()
let db = manager.get_connection();
print!("{:?}", self.admin.clone().id);
self.admin.to_owned().delete(db).await?;
Ok(())
}
}