Merge pull request #6 from EETagent/admin_rollback

Down pro vytvoření admin účtu
This commit is contained in:
Vojtěch Jungmann 2022-10-24 17:45:36 +02:00 committed by GitHub
commit c009ca9544
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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_111310_create_admin::Migration),
Box::new(m20221024_121621_create_candidate::Migration), Box::new(m20221024_121621_create_candidate::Migration),
Box::new(m20221024_124701_create_parent::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,15 +1,20 @@
use chrono::Local; use chrono::Local;
use entity::admin; use entity::admin;
use sea_orm_migration::{prelude::*, sea_orm::{Set, ActiveModelTrait}}; use sea_orm_migration::{
prelude::*,
sea_orm::{ActiveModelTrait, Set},
};
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
pub struct Migration; pub struct Migration {
admin: admin::ActiveModel,
}
#[async_trait::async_trait] impl Default for Migration {
impl MigrationTrait for Migration { fn default() -> Self {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { Self {
let db = manager.get_connection(); admin: admin::ActiveModel {
admin::ActiveModel { id: Set(1),
name: Set("Administrátor Pepa".to_owned()), name: Set("Administrátor Pepa".to_owned()),
public_key: Set("lorem ipsum".to_owned()), public_key: Set("lorem ipsum".to_owned()),
private_key_hash: Set("lorem ipsum".to_owned()), private_key_hash: Set("lorem ipsum".to_owned()),
@ -17,14 +22,28 @@ impl MigrationTrait for Migration {
created_at: Set(Local::now().naive_local()), created_at: Set(Local::now().naive_local()),
updated_at: Set(Local::now().naive_local()), updated_at: Set(Local::now().naive_local()),
..Default::default() ..Default::default()
},
} }
.insert(db) }
.await?; }
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
self.admin.to_owned().insert(db).await?;
Ok(()) Ok(())
} }
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { 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(())
} }
} }