microsandbox_db/entity/sandbox_image.rs
1//! Entity definition for the `sandbox_image` join table.
2//!
3//! Links sandboxes to their pinned images, enabling safe image GC
4//! (images referenced by running sandboxes cannot be deleted).
5
6use sea_orm::entity::prelude::*;
7
8//--------------------------------------------------------------------------------------------------
9// Types
10//--------------------------------------------------------------------------------------------------
11
12/// The sandbox-image join entity model.
13#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
14#[sea_orm(table_name = "sandbox_image")]
15pub struct Model {
16 #[sea_orm(primary_key)]
17 pub id: i32,
18 pub sandbox_id: i32,
19 pub image_id: i32,
20 pub manifest_digest: String,
21 pub created_at: Option<DateTime>,
22}
23
24//--------------------------------------------------------------------------------------------------
25// Types: Relations
26//--------------------------------------------------------------------------------------------------
27
28/// Relations for the sandbox_image entity.
29#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
30pub enum Relation {
31 /// Belongs to a sandbox.
32 #[sea_orm(
33 belongs_to = "super::sandbox::Entity",
34 from = "Column::SandboxId",
35 to = "super::sandbox::Column::Id"
36 )]
37 Sandbox,
38
39 /// Belongs to an image.
40 #[sea_orm(
41 belongs_to = "super::image::Entity",
42 from = "Column::ImageId",
43 to = "super::image::Column::Id"
44 )]
45 Image,
46}
47
48impl Related<super::sandbox::Entity> for Entity {
49 fn to() -> RelationDef {
50 Relation::Sandbox.def()
51 }
52}
53
54impl Related<super::image::Entity> for Entity {
55 fn to() -> RelationDef {
56 Relation::Image.def()
57 }
58}
59
60//--------------------------------------------------------------------------------------------------
61// Trait Implementations
62//--------------------------------------------------------------------------------------------------
63
64impl ActiveModelBehavior for ActiveModel {}