mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-26 21:41:50 +00:00
Merge pull request #6 from EETagent/admin_rollback
Down pro vytvoření admin účtu
This commit is contained in:
commit
c009ca9544
2 changed files with 34 additions and 15 deletions
|
|
@ -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()),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,49 @@
|
||||||
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
let db = manager.get_connection();
|
let db = manager.get_connection();
|
||||||
admin::ActiveModel {
|
|
||||||
name: Set("Administrátor Pepa".to_owned()),
|
self.admin.to_owned().insert(db).await?;
|
||||||
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(())
|
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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue