linkrs_storage/schema/
version_history.rs1use super::change::{ChangeLog, PropertyChange, SchemaObjectType};
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct LabelVersionHistory {
12 pub label_id: u32,
14 pub label_name: String,
16 pub object_type: SchemaObjectType,
18 pub change_log: ChangeLog,
20}
21
22impl LabelVersionHistory {
23 pub fn new(label_id: u32, label_name: String, object_type: SchemaObjectType) -> Self {
25 Self {
26 label_id,
27 label_name: label_name.clone(),
28 object_type,
29 change_log: ChangeLog::new(object_type, label_id, label_name),
30 }
31 }
32
33 pub fn add_change(&mut self, change: PropertyChange) {
35 self.change_log.add_change(change);
36 }
37
38 pub fn latest_version(&self) -> u64 {
40 self.change_log.latest_version().unwrap_or(1)
41 }
42
43 pub fn get_versions(&self) -> Vec<u64> {
45 self.change_log.get_versions()
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_label_version_history_creation() {
55 let history = LabelVersionHistory::new(1, "User".to_string(), SchemaObjectType::Vertex);
56 assert_eq!(history.label_id, 1);
57 assert_eq!(history.label_name, "User");
58 assert_eq!(history.latest_version(), 1);
59 }
60}