-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
193 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
migration/src/m20241029_154332_create_runstatus_table.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
use sea_orm_migration::prelude::*; | ||
use sea_orm_migration::sea_orm::prelude::Json; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
// Create the RunStatus table | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(RunStatus::Table) | ||
.if_not_exists() | ||
.col(ColumnDef::new(RunStatus::Id).uuid().primary_key()) | ||
.col(ColumnDef::new(RunStatus::SubmissionId).uuid().not_null()) | ||
.col(ColumnDef::new(RunStatus::KubernetesPodName).string().null()) | ||
.col(ColumnDef::new(RunStatus::Status).string().null()) | ||
.col( | ||
ColumnDef::new(RunStatus::IsRunning) | ||
.boolean() | ||
.not_null() | ||
.default(false), | ||
) | ||
.col( | ||
ColumnDef::new(RunStatus::IsSuccessful) | ||
.boolean() | ||
.not_null() | ||
.default(false), | ||
) | ||
.col( | ||
ColumnDef::new(RunStatus::IsStillKubernetesResource) | ||
.boolean() | ||
.not_null() | ||
.default(false), | ||
) | ||
.col(ColumnDef::new(RunStatus::TimeStarted).string().null()) | ||
.col( | ||
ColumnDef::new(RunStatus::Logs) | ||
.json() | ||
.not_null() | ||
.default(Json::Array(vec![])), | ||
) | ||
.col( | ||
ColumnDef::new(RunStatus::TimeAddedUtc) | ||
.date_time() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(RunStatus::LastUpdated) | ||
.date_time() | ||
.not_null(), | ||
) | ||
.foreign_key( | ||
ForeignKeyCreateStatement::new() | ||
.name("fk_run_status_submission_id") | ||
.from_tbl(RunStatus::Table) | ||
.from_col(RunStatus::SubmissionId) | ||
.to_tbl(Submissions::Table) | ||
.to_col(Submissions::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
// Create indexes for the RunStatus table | ||
manager | ||
.create_index( | ||
Index::create() | ||
.name("idx_run_status_submission_id") | ||
.table(RunStatus::Table) | ||
.col(RunStatus::SubmissionId) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.name("idx_run_status_kubernetes_pod_name") | ||
.table(RunStatus::Table) | ||
.col(RunStatus::KubernetesPodName) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.name("idx_run_status_status") | ||
.table(RunStatus::Table) | ||
.col(RunStatus::Status) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
// Drop the RunStatus table in the down migration | ||
manager | ||
.drop_table(Table::drop().table(RunStatus::Table).to_owned()) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum RunStatus { | ||
Table, | ||
Id, | ||
SubmissionId, | ||
KubernetesPodName, | ||
Status, | ||
IsRunning, | ||
IsSuccessful, | ||
IsStillKubernetesResource, | ||
TimeStarted, | ||
Logs, | ||
TimeAddedUtc, | ||
LastUpdated, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Submissions { | ||
Table, | ||
Id, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod db; | ||
pub mod models; | ||
pub mod run_status; | ||
pub mod views; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use chrono::NaiveDateTime; | ||
use sea_orm::entity::prelude::*; | ||
use uuid::Uuid; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] | ||
#[sea_orm(table_name = "run_status")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: Uuid, | ||
pub submission_id: Uuid, | ||
pub kubernetes_pod_name: Option<String>, | ||
pub status: Option<String>, | ||
pub is_running: bool, | ||
pub is_successful: bool, | ||
pub is_still_kubernetes_resource: bool, | ||
pub time_started: Option<String>, | ||
pub logs: Json, | ||
pub time_added_utc: NaiveDateTime, | ||
pub last_updated: NaiveDateTime, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "crate::submissions::db::Entity", | ||
from = "Column::SubmissionId", | ||
to = "crate::submissions::db::Column::Id" | ||
)] | ||
Submissions, | ||
} | ||
|
||
impl Related<crate::submissions::db::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Submissions.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters