Skip to content

Commit

Permalink
Fixed the Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
itsparser committed Mar 16, 2024
1 parent f5e514e commit 7e7bae6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
12 changes: 6 additions & 6 deletions crates/libs/entity/src/test/ui/log/item_log.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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<i64>,
pub log_id: Option<i32>,
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<i64>) -> ActiveModel {
pub fn new(ref_id: Uuid, ref_type: ItemLogType, step_id: Uuid, log_id: Option<i32>) -> ActiveModel {
ActiveModel {
id: NotSet,
id: Default::default(),
ref_id: Set(ref_id),
ref_type: Set(ref_type),
step_id: Set(step_id),
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/entity/src/test/ui/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub is_dry_run: bool,
pub ref_id: Uuid,
Expand All @@ -73,7 +73,7 @@ pub struct Model {

pub log_id: i32,
pub created_at: DateTimeWithTimeZone,
pub created_by: Option<String>,
pub created_by: String,
pub finished_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
}
Expand All @@ -88,7 +88,7 @@ pub fn new(
desc: Option<String>,
) -> ActiveModel {
ActiveModel {
id: NotSet,
id: Default::default(),
description: Set(desc),
is_dry_run: Set(is_dry_run),
ref_id: Set(ref_id),
Expand All @@ -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()),
}
Expand Down
32 changes: 18 additions & 14 deletions crates/libs/migration/src/migration001.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -475,7 +475,7 @@ impl MigrationTrait for Migration {
)
.col(
ColumnDef::new(item_log::Column::RefType)
.string_len(5)
.string()
.not_null(),
)
.col(
Expand All @@ -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())
Expand All @@ -524,19 +523,19 @@ impl MigrationTrait for Migration {
ColumnDef::new(request::Column::Id)
.integer()
.not_null()
.primary_key(),
.primary_key().auto_increment(),
)
.col(
ColumnDef::new(request::Column::Description)
.string(),
)
.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)
Expand All @@ -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(
Expand All @@ -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?;
Expand Down
3 changes: 3 additions & 0 deletions crates/services/api/src/service/app/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/services/engine/src/controller/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion crates/services/engine/src/controller/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down

0 comments on commit 7e7bae6

Please sign in to comment.