microsandbox_db/entity/sandbox_rootfs.rs
1//! Entity definition for the `sandbox_rootfs` table.
2//!
3//! Pins each sandbox to a manifest digest and runtime mode.
4
5use sea_orm::entity::prelude::*;
6
7//--------------------------------------------------------------------------------------------------
8// Types
9//--------------------------------------------------------------------------------------------------
10
11/// The sandbox rootfs entity model.
12#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
13#[sea_orm(table_name = "sandbox_rootfs")]
14pub struct Model {
15 #[sea_orm(primary_key)]
16 pub id: i32,
17 #[sea_orm(unique)]
18 pub sandbox_id: i32,
19 pub manifest_id: Option<i32>,
20 pub mode: String,
21 pub upper_fstype: Option<String>,
22 /// Root disk kind tag (`managed`, `tmpfs`, `disk-image`). DB default: `managed`.
23 pub root_disk_kind: String,
24 /// Host path of the user-supplied image for `disk-image` root disks.
25 pub root_disk_path: Option<String>,
26 pub created_at: Option<DateTime>,
27}
28
29/// Rootfs source mode stored in the `sandbox_rootfs.mode` column.
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub enum SandboxRootfsMode {
32 /// EROFS fsmerge + VMDK (always 2 block devices).
33 Erofs,
34 /// Host directory bind mount.
35 Bind,
36 /// Pre-existing disk image (qcow2/raw/vmdk).
37 DiskImage,
38}
39
40//--------------------------------------------------------------------------------------------------
41// Methods
42//--------------------------------------------------------------------------------------------------
43
44impl SandboxRootfsMode {
45 /// Database string representation.
46 pub fn as_str(&self) -> &'static str {
47 match self {
48 Self::Erofs => "erofs",
49 Self::Bind => "bind",
50 Self::DiskImage => "disk_image",
51 }
52 }
53
54 /// Parse from database string.
55 pub fn parse_str(s: &str) -> Option<Self> {
56 match s {
57 "erofs" => Some(Self::Erofs),
58 "bind" => Some(Self::Bind),
59 "disk_image" => Some(Self::DiskImage),
60 _ => None,
61 }
62 }
63}
64
65//--------------------------------------------------------------------------------------------------
66// Types: Relations
67//--------------------------------------------------------------------------------------------------
68
69/// Relations for the sandbox_rootfs entity.
70#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
71pub enum Relation {
72 /// Belongs to a sandbox (1:1).
73 #[sea_orm(
74 belongs_to = "super::sandbox::Entity",
75 from = "Column::SandboxId",
76 to = "super::sandbox::Column::Id",
77 on_delete = "Cascade"
78 )]
79 Sandbox,
80
81 /// References a manifest (nullable for bind/disk-image).
82 #[sea_orm(
83 belongs_to = "super::manifest::Entity",
84 from = "Column::ManifestId",
85 to = "super::manifest::Column::Id",
86 on_delete = "Restrict"
87 )]
88 Manifest,
89}
90
91impl Related<super::sandbox::Entity> for Entity {
92 fn to() -> RelationDef {
93 Relation::Sandbox.def()
94 }
95}
96
97impl Related<super::manifest::Entity> for Entity {
98 fn to() -> RelationDef {
99 Relation::Manifest.def()
100 }
101}
102
103//--------------------------------------------------------------------------------------------------
104// Trait Implementations
105//--------------------------------------------------------------------------------------------------
106
107impl ActiveModelBehavior for ActiveModel {}