Skip to main content

microsandbox_db/entity/
manifest.rs

1//! Entity definition for the `manifest` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The OCI manifest entity model.
10#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
11#[sea_orm(table_name = "manifest")]
12pub struct Model {
13    #[sea_orm(primary_key)]
14    pub id: i32,
15    #[sea_orm(unique)]
16    pub digest: String,
17    pub media_type: Option<String>,
18    pub config_digest: Option<String>,
19    pub architecture: Option<String>,
20    pub os: Option<String>,
21    pub variant: Option<String>,
22    pub layer_count: Option<i32>,
23    pub total_size_bytes: Option<i64>,
24    pub created_at: Option<DateTime>,
25}
26
27//--------------------------------------------------------------------------------------------------
28// Types: Relations
29//--------------------------------------------------------------------------------------------------
30
31/// Relations for the manifest entity.
32#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
33pub enum Relation {
34    /// A manifest has many image references (N:1 from image_ref side).
35    #[sea_orm(has_many = "super::image_ref::Entity")]
36    ImageRef,
37
38    /// A manifest has one config.
39    #[sea_orm(has_one = "super::config::Entity")]
40    Config,
41
42    /// A manifest has many manifest_layers.
43    #[sea_orm(has_many = "super::manifest_layer::Entity")]
44    ManifestLayer,
45
46    /// A manifest may be referenced by sandbox_rootfs entries.
47    #[sea_orm(has_many = "super::sandbox_rootfs::Entity")]
48    SandboxRootfs,
49}
50
51impl Related<super::image_ref::Entity> for Entity {
52    fn to() -> RelationDef {
53        Relation::ImageRef.def()
54    }
55}
56
57impl Related<super::config::Entity> for Entity {
58    fn to() -> RelationDef {
59        Relation::Config.def()
60    }
61}
62
63impl Related<super::manifest_layer::Entity> for Entity {
64    fn to() -> RelationDef {
65        Relation::ManifestLayer.def()
66    }
67}
68
69impl Related<super::layer::Entity> for Entity {
70    fn to() -> RelationDef {
71        super::manifest_layer::Relation::Layer.def()
72    }
73
74    fn via() -> Option<RelationDef> {
75        Some(super::manifest_layer::Relation::Manifest.def().rev())
76    }
77}
78
79//--------------------------------------------------------------------------------------------------
80// Trait Implementations
81//--------------------------------------------------------------------------------------------------
82
83impl ActiveModelBehavior for ActiveModel {}