microsandbox_db/entity/image_ref.rs
1//! Entity definition for the `image_ref` table.
2//!
3//! Maps OCI image references (e.g. `docker.io/library/python:3.12`) to their
4//! resolved manifest. Multiple references can share one manifest (N:1).
5
6use sea_orm::entity::prelude::*;
7
8//--------------------------------------------------------------------------------------------------
9// Types
10//--------------------------------------------------------------------------------------------------
11
12/// The OCI image reference entity model.
13#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
14#[sea_orm(table_name = "image_ref")]
15pub struct Model {
16 #[sea_orm(primary_key)]
17 pub id: i32,
18 #[sea_orm(unique)]
19 pub reference: String,
20 pub manifest_id: i32,
21 pub created_at: Option<DateTime>,
22 pub updated_at: Option<DateTime>,
23}
24
25//--------------------------------------------------------------------------------------------------
26// Types: Relations
27//--------------------------------------------------------------------------------------------------
28
29/// Relations for the image_ref entity.
30#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
31pub enum Relation {
32 /// An image reference belongs to a manifest (N:1).
33 #[sea_orm(
34 belongs_to = "super::manifest::Entity",
35 from = "Column::ManifestId",
36 to = "super::manifest::Column::Id",
37 on_delete = "Cascade"
38 )]
39 Manifest,
40}
41
42impl Related<super::manifest::Entity> for Entity {
43 fn to() -> RelationDef {
44 Relation::Manifest.def()
45 }
46}
47
48//--------------------------------------------------------------------------------------------------
49// Trait Implementations
50//--------------------------------------------------------------------------------------------------
51
52impl ActiveModelBehavior for ActiveModel {}