Skip to main content

safe_migrate/analysis/
transaction.rs

1// FILE: src/analysis/transaction.rs
2
3use crate::ast::identifiers::ObjectId;
4use crate::model::relation::RelationOverlay;
5use crate::model::sequence::SequenceOverlay;
6use crate::model::types::TypeOverlay;
7// Added RenameEdge here to support the new RenameGraphSnapshot
8use crate::analysis::graph::{
9    FkEdge, IndexEdge, PartitionEdge, RenameEdge, SequenceEdge, ViewEdge,
10};
11// Added HashSet to support the PendingValidationSnapshot
12use std::collections::HashSet;
13
14#[derive(Debug, Clone)]
15pub enum StateChange {
16    RelationSnapshot {
17        id: ObjectId,
18        previous: Option<RelationOverlay>,
19    },
20    TypeSnapshot {
21        id: ObjectId,
22        previous: Option<TypeOverlay>,
23    },
24    SequenceSnapshot {
25        id: ObjectId,
26        previous: Option<SequenceOverlay>,
27    },
28    SearchPathSnapshot {
29        previous: Vec<String>,
30    },
31
32    // Phase 2 FIX (BUG-001, BUG-002): Transactional integrity for counters and validations
33    GenerationCounterSnapshot {
34        previous: u64,
35    },
36    PendingValidationSnapshot {
37        previous: HashSet<(ObjectId, String)>,
38    },
39
40    FkGraphLengthMarker {
41        len: usize,
42    },
43    FkGraphSnapshot {
44        previous: Vec<FkEdge>,
45    },
46    ViewGraphLengthMarker {
47        len: usize,
48    },
49    ViewGraphSnapshot {
50        previous: Vec<ViewEdge>,
51    },
52    IndexGraphLengthMarker {
53        len: usize,
54    },
55    IndexGraphSnapshot {
56        previous: Vec<IndexEdge>,
57    },
58    RenameGraphLengthMarker {
59        len: usize,
60    },
61
62    // Phase 2 FIX (BUG-008): Missing snapshot for schema drops
63    RenameGraphSnapshot {
64        previous: Vec<RenameEdge>,
65    },
66
67    SequenceGraphLengthMarker {
68        len: usize,
69    },
70    SequenceGraphSnapshot {
71        previous: Vec<SequenceEdge>,
72    },
73    PartitionGraphLengthMarker {
74        len: usize,
75    },
76    PartitionGraphSnapshot {
77        previous: Vec<PartitionEdge>,
78    },
79}
80
81#[derive(Debug, Clone)]
82pub struct TransactionFrame {
83    pub name: String,
84    pub undo_log: Vec<StateChange>,
85}
86
87impl TransactionFrame {
88    pub fn new(name: impl Into<String>) -> Self {
89        Self {
90            name: name.into(),
91            undo_log: Vec::new(),
92        }
93    }
94}