From 7e7bae6d629662e5c383e06ad8e9ea0e669299ab Mon Sep 17 00:00:00 2001 From: Vasanth kumar Kalaiselvan Date: Sat, 16 Mar 2024 16:53:31 +0530 Subject: [PATCH] Fixed the Migration --- .../libs/entity/src/test/ui/log/item_log.rs | 12 +++---- crates/libs/entity/src/test/ui/request.rs | 8 ++--- crates/libs/migration/src/migration001.rs | 32 +++++++++++-------- crates/services/api/src/service/app/case.rs | 3 ++ .../services/engine/src/controller/action.rs | 4 +-- crates/services/engine/src/controller/case.rs | 2 +- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/crates/libs/entity/src/test/ui/log/item_log.rs b/crates/libs/entity/src/test/ui/log/item_log.rs index eab5bce..fc566f5 100644 --- a/crates/libs/entity/src/test/ui/log/item_log.rs +++ b/crates/libs/entity/src/test/ui/log/item_log.rs @@ -1,8 +1,8 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.6.0 -use sea_orm::{EntityTrait, NotSet}; use sea_orm::ActiveValue::Set; use sea_orm::entity::prelude::*; +use sea_orm::EntityTrait; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Deserialize, Serialize)] @@ -44,24 +44,24 @@ pub enum ItemLogType { pub struct Model { #[serde(skip_deserializing)] #[sea_orm(primary_key)] - pub id: i64, + pub id: i32, pub ref_id: Uuid, pub ref_type: ItemLogType, pub step_id: Uuid, pub has_screenshot: bool, pub has_recording: bool, - pub execution_time: i64, + pub execution_time: i32, pub status: ItemLogStatus, - pub log_id: Option, + pub log_id: Option, pub created_at: DateTimeWithTimeZone, pub created_by: String, pub finished_at: DateTimeWithTimeZone, } -pub fn new(ref_id: Uuid, ref_type: ItemLogType, step_id: Uuid, log_id: Option) -> ActiveModel { +pub fn new(ref_id: Uuid, ref_type: ItemLogType, step_id: Uuid, log_id: Option) -> ActiveModel { ActiveModel { - id: NotSet, + id: Default::default(), ref_id: Set(ref_id), ref_type: Set(ref_type), step_id: Set(step_id), diff --git a/crates/libs/entity/src/test/ui/request.rs b/crates/libs/entity/src/test/ui/request.rs index 8daa43d..ab585da 100644 --- a/crates/libs/entity/src/test/ui/request.rs +++ b/crates/libs/entity/src/test/ui/request.rs @@ -61,7 +61,7 @@ pub enum ExecutionStatus { pub struct Model { #[serde(skip_deserializing)] #[sea_orm(primary_key)] - pub id: i64, + pub id: i32, pub description: Option, pub is_dry_run: bool, pub ref_id: Uuid, @@ -73,7 +73,7 @@ pub struct Model { pub log_id: i32, pub created_at: DateTimeWithTimeZone, - pub created_by: Option, + pub created_by: String, pub finished_at: DateTimeWithTimeZone, pub updated_at: DateTimeWithTimeZone, } @@ -88,7 +88,7 @@ pub fn new( desc: Option, ) -> ActiveModel { ActiveModel { - id: NotSet, + id: Default::default(), description: Set(desc), is_dry_run: Set(is_dry_run), ref_id: Set(ref_id), @@ -98,7 +98,7 @@ pub fn new( args: NotSet, log_id: Set(log_id), created_at: Set(chrono::Utc::now().into()), - created_by: NotSet, + created_by: Set("System".to_string()), finished_at: Set(chrono::Utc::now().into()), updated_at: Set(chrono::Utc::now().into()), } diff --git a/crates/libs/migration/src/migration001.rs b/crates/libs/migration/src/migration001.rs index 393fd0b..fc3c2f1 100644 --- a/crates/libs/migration/src/migration001.rs +++ b/crates/libs/migration/src/migration001.rs @@ -466,7 +466,7 @@ impl MigrationTrait for Migration { ColumnDef::new(item_log::Column::Id) .integer() .not_null() - .primary_key(), + .primary_key().auto_increment(), ) .col( ColumnDef::new(item_log::Column::RefId) @@ -475,7 +475,7 @@ impl MigrationTrait for Migration { ) .col( ColumnDef::new(item_log::Column::RefType) - .string_len(5) + .string() .not_null(), ) .col( @@ -500,13 +500,12 @@ impl MigrationTrait for Migration { ) .col( ColumnDef::new(item_log::Column::Status) - .string_len(5) + .string() .not_null(), ) .col( ColumnDef::new(item_log::Column::LogId) - .integer() - .not_null(), + .integer(), ) .col(ColumnDef::new(item_log::Column::CreatedBy).string().not_null()) .col(ColumnDef::new(item_log::Column::CreatedAt).timestamp_with_time_zone().not_null()) @@ -524,7 +523,7 @@ impl MigrationTrait for Migration { ColumnDef::new(request::Column::Id) .integer() .not_null() - .primary_key(), + .primary_key().auto_increment(), ) .col( ColumnDef::new(request::Column::Description) @@ -532,11 +531,11 @@ impl MigrationTrait for Migration { ) .col( ColumnDef::new(request::Column::IsDryRun) - .boolean(), + .boolean().default(false), ) .col( ColumnDef::new(request::Column::RefType) - .string_len(5).not_null(), + .string().not_null(), ) .col( ColumnDef::new(request::Column::RefId) @@ -545,7 +544,12 @@ impl MigrationTrait for Migration { ) .col( ColumnDef::new(request::Column::Kind) - .string_len(10) + .string() + .not_null(), + ) + .col( + ColumnDef::new(request::Column::Status) + .string() .not_null(), ) .col( @@ -554,12 +558,12 @@ impl MigrationTrait for Migration { ) .col( ColumnDef::new(request::Column::LogId) - .integer() - .not_null(), + .integer(), ) - .col(ColumnDef::new(item_log::Column::CreatedBy).string().not_null()) - .col(ColumnDef::new(item_log::Column::CreatedAt).timestamp_with_time_zone().not_null()) - .col(ColumnDef::new(item_log::Column::FinishedAt).timestamp_with_time_zone().not_null()) + .col(ColumnDef::new(request::Column::CreatedBy).string().not_null()) + .col(ColumnDef::new(request::Column::CreatedAt).timestamp_with_time_zone().not_null()) + .col(ColumnDef::new(request::Column::UpdatedAt).timestamp_with_time_zone().not_null()) + .col(ColumnDef::new(request::Column::FinishedAt).timestamp_with_time_zone().not_null()) .to_owned(), ) .await?; diff --git a/crates/services/api/src/service/app/case.rs b/crates/services/api/src/service/app/case.rs index 3770d62..d613e79 100644 --- a/crates/services/api/src/service/app/case.rs +++ b/crates/services/api/src/service/app/case.rs @@ -192,6 +192,7 @@ impl CaseService { /// run - this will run the single tes case pub async fn run(&self, case_id: Uuid) -> InternalResult<()> { let case = Entity::find_by_id(case_id).one(self.trx()).await?; + debug!("run {:?}", case); if case.is_none() { return Err(OrcaRepoError::ModelNotFound( "Test Case".to_string(), @@ -214,7 +215,9 @@ impl CaseService { // finished_at: None, // updated_at: None, // }; + let mut er_am = er_am.save(self.trx()).await?; + debug!("run 2 {:?}", er_am); let ui_driver = WebDriver::default().await?; let controller = CaseController::new(self.trx(), ui_driver.clone(), self.1.clone()); let er = er_am.clone().try_into_model()?; diff --git a/crates/services/engine/src/controller/action.rs b/crates/services/engine/src/controller/action.rs index 1e17731..0d70dc1 100644 --- a/crates/services/engine/src/controller/action.rs +++ b/crates/services/engine/src/controller/action.rs @@ -279,7 +279,7 @@ impl<'ccl> ActionController<'ccl> { "Done step == [id] {:?}, [desc] {:?}", action.id, action.description ); - log_am.execution_time = Set((chrono::Utc::now() - start).num_milliseconds()); + log_am.execution_time = Set((chrono::Utc::now() - start).num_milliseconds() as i32); log_am.status = Set(ItemLogStatus::Success); log_am.finished_at = Set(chrono::Utc::now().into()); log_am.save(self.db).await?; @@ -316,7 +316,7 @@ impl<'ccl> ActionController<'ccl> { let log = log_am.clone().try_into_model()?; self.execute_action_group(action_group, er, Some(&log)).await?; - log_am.execution_time = Set((chrono::Utc::now() - start).num_milliseconds()); + log_am.execution_time = Set((chrono::Utc::now() - start).num_milliseconds() as i32); log_am.status = Set(ItemLogStatus::Success); log_am.finished_at = Set(chrono::Utc::now().into()); log_am.save(self.db).await?; diff --git a/crates/services/engine/src/controller/case.rs b/crates/services/engine/src/controller/case.rs index e2cfff9..7c64f4d 100644 --- a/crates/services/engine/src/controller/case.rs +++ b/crates/services/engine/src/controller/case.rs @@ -64,7 +64,7 @@ impl<'ccl> CaseController<'ccl> { let log = log_am.clone().try_into_model()?; self.process(&case, er, Some(&log)).await?; - log_am.execution_time = Set((chrono::Utc::now() - start).num_milliseconds()); + log_am.execution_time = Set((chrono::Utc::now() - start).num_milliseconds() as i32); log_am.status = Set(ItemLogStatus::Success); log_am.finished_at = Set(chrono::Utc::now().into()); log_am.save(self.db).await?;