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
60impl Related<super::run::Entity> for Entity {
61 fn to() -> RelationDef {
62 Relation::Run.def()
63 }
64}
65
66//--------------------------------------------------------------------------------------------------
67// Trait Implementations
68//--------------------------------------------------------------------------------------------------
69
70impl ActiveModelBehavior for ActiveModel {}