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    ColumnDependencyEdge, FkEdge, IndexEdge, PartitionEdge, PublicationEdge, RenameEdge,
10    SequenceEdge, ViewEdge,
11};
12// Added HashSet to support the PendingValidationSnapshot
13use std::collections::HashSet;
14
15#[derive(Debug, Clone)]
16pub enum StateChange {
17    RelationSnapshot {
18        id: ObjectId,
19        previous: Box<Option<RelationOverlay>>,
20    },
21    TypeSnapshot {
22        id: ObjectId,
23        previous: Option<TypeOverlay>,
24    },
25    SequenceSnapshot {
26        id: ObjectId,
27        previous: Option<SequenceOverlay>,
28    },
29    SearchPathSnapshot {
30        previous: Vec<String>,
31    },
32
33    // Phase 2 FIX (BUG-001, BUG-002): Transactional integrity for counters and validations
34    GenerationCounterSnapshot {
35        previous: u64,
36    },
37    PendingValidationSnapshot {
38        previous: HashSet<(ObjectId, String)>,
39    },
40
41    FkGraphLengthMarker {
42        len: usize,
43    },
44    FkGraphSnapshot {
45        previous: Vec<FkEdge>,
46    },
47    ViewGraphLengthMarker {
48        len: usize,
49    },
50    ViewGraphSnapshot {
51        previous: Vec<ViewEdge>,
52    },
53    IndexGraphLengthMarker {
54        len: usize,
55    },
56    IndexGraphSnapshot {
57        previous: Vec<IndexEdge>,
58    },
59    RenameGraphLengthMarker {
60        len: usize,
61    },
62
63    // Phase 2 FIX (BUG-008): Missing snapshot for schema drops
64    RenameGraphSnapshot {
65        previous: Vec<RenameEdge>,
66    },
67
68    SequenceGraphLengthMarker {
69        len: usize,
70    },
71    SequenceGraphSnapshot {
72        previous: Vec<SequenceEdge>,
73    },
74    ColumnGraphLengthMarker {
75        len: usize,
76    },
77    ColumnGraphSnapshot {
78        previous: Vec<ColumnDependencyEdge>,
79    },
80    PartitionGraphMarker {
81        len: usize,
82    },
83    PartitionGraphSnapshot {
84        previous: Vec<PartitionEdge>,
85    },
86    FunctionSnapshot {
87        id: ObjectId,
88        previous: Option<crate::model::function::FunctionOverlay>,
89    },
90    PublicationSnapshot {
91        id: ObjectId,
92        previous: Option<crate::model::replication::PublicationOverlay>,
93    },
94    SubscriptionSnapshot {
95        id: ObjectId,
96        previous: Option<crate::model::replication::SubscriptionOverlay>,
97    },
98    RoleSnapshot {
99        id: ObjectId,
100        previous: Option<crate::model::role::RoleOverlay>,
101    },
102    TriggerSnapshot {
103        id: ObjectId,
104        previous: Option<crate::model::trigger::TriggerOverlay>,
105    },
106    TriggerGraphSnapshot {
107        previous: Vec<crate::analysis::graph::TriggerEdge>,
108    },
109    PublicationGraphSnapshot {
110        previous: Vec<PublicationEdge>,
111    },
112    CurrentRoleSnapshot {
113        previous: String,
114    },
115    ConfidenceSnapshot {
116        previous: crate::analysis::state::Confidence,
117    },
118}
119
120#[derive(Debug, Clone)]
121pub struct TransactionFrame {
122    pub name: String,
123    pub undo_log: Vec<StateChange>,
124}
125
126impl TransactionFrame {
127    pub fn new(name: impl Into<String>) -> Self {
128        Self {
129            name: name.into(),
130            undo_log: Vec::new(),
131        }
132    }
133}