Skip to main content

microsandbox_db/entity/
snapshot.rs

1//! Entity definition for the `snapshots` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The snapshot entity model.
10#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
11#[sea_orm(table_name = "snapshot")]
12pub struct Model {
13    #[sea_orm(primary_key)]
14    pub id: i32,
15    pub name: String,
16    pub sandbox_id: Option<i32>,
17    pub size_bytes: Option<i64>,
18    pub description: Option<String>,
19    pub created_at: Option<DateTime>,
20}
21
22//--------------------------------------------------------------------------------------------------
23// Types: Relations
24//--------------------------------------------------------------------------------------------------
25
26/// Relations for the snapshot entity.
27#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
28pub enum Relation {
29    /// A snapshot optionally belongs to a sandbox.
30    #[sea_orm(
31        belongs_to = "super::sandbox::Entity",
32        from = "Column::SandboxId",
33        to = "super::sandbox::Column::Id",
34        on_delete = "SetNull"
35    )]
36    Sandbox,
37}
38
39impl Related<super::sandbox::Entity> for Entity {
40    fn to() -> RelationDef {
41        Relation::Sandbox.def()
42    }
43}
44
45//--------------------------------------------------------------------------------------------------
46// Trait Implementations
47//--------------------------------------------------------------------------------------------------
48
49impl ActiveModelBehavior for ActiveModel {}