Skip to main content

microsandbox_db/entity/
layer.rs

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