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 (`snapshot.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 /// Snapshot payload scope (`disk` today, `resumable` in the future).
25 pub scope: String,
26 /// Closed descriptor state discriminant (`file` or `checkpoint`).
27 pub state_kind: String,
28 /// Human-readable image reference.
29 pub image_ref: String,
30 /// OCI manifest digest of the image.
31 pub image_manifest_digest: String,
32 /// On-disk format of the upper layer (`raw` or `qcow2`).
33 pub format: Option<String>,
34 /// Filesystem type inside the upper (e.g. `ext4`).
35 pub fstype: Option<String>,
36 /// Checkpoint-manifest digest for checkpoint state.
37 pub checkpoint_manifest_digest: Option<String>,
38 /// Absolute path to the artifact directory on this host.
39 pub artifact_path: String,
40 /// Apparent size of the upper file in bytes.
41 pub size_bytes: Option<i64>,
42 /// Locality of the state closure (`embedded` or `linked`).
43 pub locality: String,
44 /// Host-local storage/provider binding identifier.
45 pub storage_binding_id: Option<String>,
46 /// Rebuildable closure availability projection.
47 pub availability: String,
48 /// Artifact migration status projection.
49 pub migration_state: String,
50 /// Stable migration failure code when blocked.
51 pub migration_error_code: Option<String>,
52 /// Snapshot creation time (from manifest).
53 pub created_at: DateTime,
54 /// When this row was inserted/refreshed.
55 pub indexed_at: DateTime,
56 /// Number of indexed snapshots whose `parent_digest == self.digest`.
57 pub child_count: i32,
58}
59
60//--------------------------------------------------------------------------------------------------
61// Types: Relations
62//--------------------------------------------------------------------------------------------------
63
64#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
65pub enum Relation {}
66
67//--------------------------------------------------------------------------------------------------
68// Trait Implementations
69//--------------------------------------------------------------------------------------------------
70
71impl ActiveModelBehavior for ActiveModel {}