Skip to main content

microsandbox_db/entity/
sandbox.rs

1//! Entity definition for the `sandboxes` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The status of a sandbox.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
11#[sea_orm(rs_type = "String", db_type = "Text")]
12pub enum SandboxStatus {
13    /// The sandbox is running.
14    #[sea_orm(string_value = "Running")]
15    Running,
16
17    /// The sandbox is draining (shutting down gracefully).
18    #[sea_orm(string_value = "Draining")]
19    Draining,
20
21    /// The sandbox is paused.
22    #[sea_orm(string_value = "Paused")]
23    Paused,
24
25    /// The sandbox is stopped.
26    #[sea_orm(string_value = "Stopped")]
27    Stopped,
28
29    /// The sandbox crashed.
30    #[sea_orm(string_value = "Crashed")]
31    Crashed,
32}
33
34/// The sandbox entity model.
35#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
36#[sea_orm(table_name = "sandbox")]
37pub struct Model {
38    #[sea_orm(primary_key)]
39    pub id: i32,
40    #[sea_orm(unique)]
41    pub name: String,
42    pub config: String,
43    pub status: SandboxStatus,
44    pub created_at: Option<DateTime>,
45    pub updated_at: Option<DateTime>,
46}
47
48//--------------------------------------------------------------------------------------------------
49// Types: Relations
50//--------------------------------------------------------------------------------------------------
51
52/// Relations for the sandbox entity.
53#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
54pub enum Relation {
55    /// A sandbox has many runs.
56    #[sea_orm(has_many = "super::run::Entity")]
57    Run,
58
59    /// A sandbox has many metrics.
60    #[sea_orm(has_many = "super::sandbox_metric::Entity")]
61    SandboxMetric,
62
63    /// A sandbox has many snapshots.
64    #[sea_orm(has_many = "super::snapshot::Entity")]
65    Snapshot,
66}
67
68impl Related<super::run::Entity> for Entity {
69    fn to() -> RelationDef {
70        Relation::Run.def()
71    }
72}
73
74impl Related<super::sandbox_metric::Entity> for Entity {
75    fn to() -> RelationDef {
76        Relation::SandboxMetric.def()
77    }
78}
79
80impl Related<super::snapshot::Entity> for Entity {
81    fn to() -> RelationDef {
82        Relation::Snapshot.def()
83    }
84}
85
86//--------------------------------------------------------------------------------------------------
87// Trait Implementations
88//--------------------------------------------------------------------------------------------------
89
90impl ActiveModelBehavior for ActiveModel {}