Skip to main content

microsandbox_db/entity/
layer.rs

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