microsandbox_db/entity/sandbox_metric.rs
1//! Entity definition for the `sandbox_metrics` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The sandbox metrics entity model.
10#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
11#[sea_orm(table_name = "sandbox_metric")]
12pub struct Model {
13 #[sea_orm(primary_key)]
14 pub id: i32,
15 pub sandbox_id: i32,
16 pub cpu_percent: Option<f32>,
17 pub memory_bytes: Option<i64>,
18 pub disk_read_bytes: Option<i64>,
19 pub disk_write_bytes: Option<i64>,
20 pub net_rx_bytes: Option<i64>,
21 pub net_tx_bytes: Option<i64>,
22 pub sampled_at: Option<DateTime>,
23 pub created_at: Option<DateTime>,
24}
25
26//--------------------------------------------------------------------------------------------------
27// Types: Relations
28//--------------------------------------------------------------------------------------------------
29
30/// Relations for the sandbox_metric entity.
31#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
32pub enum Relation {
33 /// A metric belongs to a sandbox.
34 #[sea_orm(
35 belongs_to = "super::sandbox::Entity",
36 from = "Column::SandboxId",
37 to = "super::sandbox::Column::Id",
38 on_delete = "Cascade"
39 )]
40 Sandbox,
41}
42
43impl Related<super::sandbox::Entity> for Entity {
44 fn to() -> RelationDef {
45 Relation::Sandbox.def()
46 }
47}
48
49//--------------------------------------------------------------------------------------------------
50// Trait Implementations
51//--------------------------------------------------------------------------------------------------
52
53impl ActiveModelBehavior for ActiveModel {}