Skip to main content

microsandbox_db/entity/
index.rs

1//! Entity definition for the `indexes` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The OCI index entity model.
10#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
11#[sea_orm(table_name = "index")]
12pub struct Model {
13    #[sea_orm(primary_key)]
14    pub id: i32,
15    pub image_id: i32,
16    pub schema_version: Option<i32>,
17    pub media_type: Option<String>,
18    pub platform_os: Option<String>,
19    pub platform_arch: Option<String>,
20    pub platform_variant: Option<String>,
21    pub annotations: Option<String>,
22    pub created_at: Option<DateTime>,
23}
24
25//--------------------------------------------------------------------------------------------------
26// Types: Relations
27//--------------------------------------------------------------------------------------------------
28
29/// Relations for the index entity.
30#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
31pub enum Relation {
32    /// An index belongs to an image.
33    #[sea_orm(
34        belongs_to = "super::image::Entity",
35        from = "Column::ImageId",
36        to = "super::image::Column::Id",
37        on_delete = "Cascade"
38    )]
39    Image,
40
41    /// An index has many manifests.
42    #[sea_orm(has_many = "super::manifest::Entity")]
43    Manifest,
44}
45
46impl Related<super::image::Entity> for Entity {
47    fn to() -> RelationDef {
48        Relation::Image.def()
49    }
50}
51
52impl Related<super::manifest::Entity> for Entity {
53    fn to() -> RelationDef {
54        Relation::Manifest.def()
55    }
56}
57
58//--------------------------------------------------------------------------------------------------
59// Trait Implementations
60//--------------------------------------------------------------------------------------------------
61
62impl ActiveModelBehavior for ActiveModel {}