microsandbox_db/entity/image.rs
1//! Entity definition for the `images` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The OCI image entity model.
10#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
11#[sea_orm(table_name = "image")]
12pub struct Model {
13 #[sea_orm(primary_key)]
14 pub id: i32,
15 #[sea_orm(unique)]
16 pub reference: String,
17 pub size_bytes: Option<i64>,
18 pub last_used_at: Option<DateTime>,
19 pub created_at: Option<DateTime>,
20}
21
22//--------------------------------------------------------------------------------------------------
23// Types: Relations
24//--------------------------------------------------------------------------------------------------
25
26/// Relations for the image entity.
27#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
28pub enum Relation {
29 /// An image has many indexes.
30 #[sea_orm(has_many = "super::index::Entity")]
31 Index,
32
33 /// An image has many manifests.
34 #[sea_orm(has_many = "super::manifest::Entity")]
35 Manifest,
36}
37
38impl Related<super::index::Entity> for Entity {
39 fn to() -> RelationDef {
40 Relation::Index.def()
41 }
42}
43
44impl Related<super::manifest::Entity> for Entity {
45 fn to() -> RelationDef {
46 Relation::Manifest.def()
47 }
48}
49
50//--------------------------------------------------------------------------------------------------
51// Trait Implementations
52//--------------------------------------------------------------------------------------------------
53
54impl ActiveModelBehavior for ActiveModel {}