microsandbox_db/entity/cpu_allocation.rs
1//! Entity definition for active cooperative CPU allocations.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// One active managed CPU allocation owned by a sandbox run.
10#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
11#[sea_orm(table_name = "cpu_allocation")]
12pub struct Model {
13 /// Cryptographically random allocation identifier.
14 #[sea_orm(primary_key, auto_increment = false)]
15 pub id: String,
16 /// Owning run row.
17 pub run_id: i32,
18 /// Policy requested by the caller.
19 pub requested_policy: String,
20 /// Policy selected by the planner.
21 pub resolved_policy: String,
22 /// Host enforcement class.
23 pub enforcement: String,
24 /// Fingerprint of the topology used for planning.
25 pub topology_fingerprint: String,
26 /// Owner-only lock-file basename held for the process lifetime.
27 pub lease_name: String,
28 /// Allocation lifecycle state.
29 pub state: String,
30 /// Allocation creation time.
31 pub created_at: DateTime,
32}
33
34/// Relations for a CPU allocation.
35#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
36pub enum Relation {
37 /// The allocation belongs to one sandbox run.
38 #[sea_orm(
39 belongs_to = "super::run::Entity",
40 from = "Column::RunId",
41 to = "super::run::Column::Id",
42 on_delete = "Cascade"
43 )]
44 Run,
45}
46
47//--------------------------------------------------------------------------------------------------
48// Trait Implementations
49//--------------------------------------------------------------------------------------------------
50
51impl Related<super::run::Entity> for Entity {
52 fn to() -> RelationDef {
53 Relation::Run.def()
54 }
55}
56
57impl ActiveModelBehavior for ActiveModel {}