1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Staging area (index) for the next commit.
//!
//! The index tracks a proposed schema change before it is committed.
//! The staging pipeline validates the migration and produces a
//! compatibility report.
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::gat_validate::GatDiagnostics;
use crate::hash::ObjectId;
/// The staging area for the next commit.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Index {
/// The schema staged for the next commit, if any.
pub staged: Option<StagedSchema>,
/// Data files staged for the next commit.
#[serde(default)]
pub staged_data: Vec<StagedData>,
/// Protocol definition staged for the next commit.
#[serde(default)]
pub staged_protocol: Option<ObjectId>,
}
/// A data file that has been staged for commit.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StagedData {
/// Path to the source data file.
pub source_path: PathBuf,
/// Object ID of the stored data set.
pub data_id: ObjectId,
/// Object ID of the schema this data conforms to.
pub schema_id: ObjectId,
}
/// A schema that has been staged for commit.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StagedSchema {
/// Object ID of the staged schema.
pub schema_id: ObjectId,
/// Object ID of the migration from HEAD's schema (if HEAD exists).
pub migration_id: Option<ObjectId>,
/// Whether the migration was automatically derived.
pub auto_derived: bool,
/// Validation status from the staging pipeline.
pub validation: ValidationStatus,
/// GAT-level diagnostics from type-checking and equation verification.
#[serde(default)]
pub gat_diagnostics: Option<GatDiagnostics>,
}
/// Result of the staging validation pipeline.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ValidationStatus {
/// Validation has not been run.
Pending,
/// The staged schema and migration are valid.
Valid,
/// Validation found errors.
Invalid(Vec<String>),
}
impl Index {
/// Returns `true` if something is staged.
#[must_use]
pub fn has_staged(&self) -> bool {
self.staged.is_some() || !self.staged_data.is_empty() || self.staged_protocol.is_some()
}
/// Clear the staging area.
pub fn clear(&mut self) {
self.staged = None;
self.staged_data.clear();
self.staged_protocol = None;
}
}