microsandbox_db/entity/snapshot.rs
1//! Entity definition for the `snapshot_index` table.
2//!
3//! This table is a local cache that mirrors snapshot artifacts on disk.
4//! The artifact (`manifest.json` + upper file) is the source of truth;
5//! these rows exist for fast queries and parent-edge bookkeeping.
6
7use sea_orm::entity::prelude::*;
8
9//--------------------------------------------------------------------------------------------------
10// Types
11//--------------------------------------------------------------------------------------------------
12
13/// The snapshot-index entity model.
14#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
15#[sea_orm(table_name = "snapshot_index")]
16pub struct Model {
17 /// Manifest digest (`sha256:hex`). Canonical snapshot identity.
18 #[sea_orm(primary_key, auto_increment = false)]
19 pub digest: String,
20 /// Convenience name (unique when present). NULL for digest-only entries.
21 pub name: Option<String>,
22 /// Manifest digest of the parent snapshot, or NULL for a root.
23 pub parent_digest: Option<String>,
24 /// Human-readable image reference.
25 pub image_ref: String,
26 /// OCI manifest digest of the image.
27 pub image_manifest_digest: String,
28 /// On-disk format of the upper layer (`raw` or `qcow2`).
29 pub format: String,
30 /// Filesystem type inside the upper (e.g. `ext4`).
31 pub fstype: String,
32 /// Absolute path to the artifact directory on this host.
33 pub artifact_path: String,
34 /// Apparent size of the upper file in bytes.
35 pub size_bytes: Option<i64>,
36 /// Snapshot creation time (from manifest).
37 pub created_at: DateTime,
38 /// When this row was inserted/refreshed.
39 pub indexed_at: DateTime,
40 /// Number of indexed snapshots whose `parent_digest == self.digest`.
41 pub child_count: i32,
42}
43
44//--------------------------------------------------------------------------------------------------
45// Types: Relations
46//--------------------------------------------------------------------------------------------------
47
48#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
49pub enum Relation {}
50
51//--------------------------------------------------------------------------------------------------
52// Trait Implementations
53//--------------------------------------------------------------------------------------------------
54
55impl ActiveModelBehavior for ActiveModel {}