use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "sandbox_rootfs")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(unique)]
pub sandbox_id: i32,
pub manifest_id: Option<i32>,
pub mode: String,
pub upper_fstype: Option<String>,
pub created_at: Option<DateTime>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SandboxRootfsMode {
Erofs,
Bind,
DiskImage,
}
impl SandboxRootfsMode {
pub fn as_str(&self) -> &'static str {
match self {
Self::Erofs => "erofs",
Self::Bind => "bind",
Self::DiskImage => "disk_image",
}
}
pub fn parse_str(s: &str) -> Option<Self> {
match s {
"erofs" => Some(Self::Erofs),
"bind" => Some(Self::Bind),
"disk_image" => Some(Self::DiskImage),
_ => None,
}
}
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::sandbox::Entity",
from = "Column::SandboxId",
to = "super::sandbox::Column::Id",
on_delete = "Cascade"
)]
Sandbox,
#[sea_orm(
belongs_to = "super::manifest::Entity",
from = "Column::ManifestId",
to = "super::manifest::Column::Id",
on_delete = "Restrict"
)]
Manifest,
}
impl Related<super::sandbox::Entity> for Entity {
fn to() -> RelationDef {
Relation::Sandbox.def()
}
}
impl Related<super::manifest::Entity> for Entity {
fn to() -> RelationDef {
Relation::Manifest.def()
}
}
impl ActiveModelBehavior for ActiveModel {}