yeti_types/schema/diff.rs
1//! Schema diff and fingerprint types for schema reconciliation.
2
3use super::field::IndexConfig;
4
5// ============================================================================
6// Schema diff
7// ============================================================================
8
9/// Result of comparing current schema against a stored fingerprint.
10#[derive(Debug, Default, Clone)]
11pub struct SchemaDiff {
12 /// Fields removed from schema → strip from stored records
13 pub strip_fields: Vec<String>,
14 /// New fields with @default → inject default value into existing records
15 pub inject_defaults: Vec<(String, serde_json::Value)>,
16 /// Fields that gained @indexed → build secondary index entries
17 pub build_indexes: Vec<(String, IndexConfig)>,
18 /// Fields that lost @indexed → delete index entries
19 pub drop_indexes: Vec<String>,
20}
21
22impl SchemaDiff {
23 /// Returns true if there are no schema changes requiring reconciliation.
24 #[must_use]
25 pub const fn is_empty(&self) -> bool {
26 self.strip_fields.is_empty()
27 && self.inject_defaults.is_empty()
28 && self.build_indexes.is_empty()
29 && self.drop_indexes.is_empty()
30 }
31}
32
33/// Stored schema fingerprint — persisted in `RocksDB` metadata.
34#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
35pub struct SchemaFingerprint {
36 /// Hash of the schema-relevant fields
37 pub hash: String,
38 /// Field names at time of fingerprinting
39 pub fields: Vec<String>,
40 /// Indexed field names at time of fingerprinting
41 pub indexed: Vec<String>,
42}