jellyflow_runtime/schema/migration/
report.rs1use jellyflow_core::core::{NodeId, NodeKindKey};
2use jellyflow_core::ops::GraphTransaction;
3
4#[derive(Debug, Default, Clone)]
5pub struct MigrateNodesReport {
6 pub upgraded: Vec<NodeMigrationUpgraded>,
7 pub missing_schema: Vec<NodeMigrationMissingSchema>,
8 pub missing_migrator: Vec<NodeMigrationMissingMigrator>,
9 pub newer_than_schema: Vec<NodeMigrationNewerThanSchema>,
10 pub errors: Vec<NodeMigrationErrorEntry>,
11}
12
13impl MigrateNodesReport {
14 pub fn is_empty(&self) -> bool {
15 self.upgraded.is_empty()
16 && self.missing_schema.is_empty()
17 && self.missing_migrator.is_empty()
18 && self.newer_than_schema.is_empty()
19 && self.errors.is_empty()
20 }
21
22 pub fn upgraded(&self) -> &[NodeMigrationUpgraded] {
23 &self.upgraded
24 }
25
26 pub fn missing_schema(&self) -> &[NodeMigrationMissingSchema] {
27 &self.missing_schema
28 }
29
30 pub fn missing_migrator(&self) -> &[NodeMigrationMissingMigrator] {
31 &self.missing_migrator
32 }
33
34 pub fn newer_than_schema(&self) -> &[NodeMigrationNewerThanSchema] {
35 &self.newer_than_schema
36 }
37
38 pub fn errors(&self) -> &[NodeMigrationErrorEntry] {
39 &self.errors
40 }
41
42 pub(in crate::schema) fn push_upgraded(
43 &mut self,
44 node: NodeId,
45 kind: NodeKindKey,
46 from: u32,
47 to: u32,
48 ) {
49 self.upgraded.push(NodeMigrationUpgraded {
50 node,
51 kind,
52 from,
53 to,
54 });
55 }
56
57 pub(in crate::schema) fn push_missing_schema(&mut self, node: NodeId, kind: NodeKindKey) {
58 self.missing_schema
59 .push(NodeMigrationMissingSchema { node, kind });
60 }
61
62 pub(in crate::schema) fn push_missing_migrator(
63 &mut self,
64 node: NodeId,
65 kind: NodeKindKey,
66 from: u32,
67 to: u32,
68 ) {
69 self.missing_migrator.push(NodeMigrationMissingMigrator {
70 node,
71 kind,
72 from,
73 to,
74 });
75 }
76
77 pub(in crate::schema) fn push_newer_than_schema(
78 &mut self,
79 node: NodeId,
80 kind: NodeKindKey,
81 node_kind_version: u32,
82 schema_latest_kind_version: u32,
83 ) {
84 self.newer_than_schema.push(NodeMigrationNewerThanSchema {
85 node,
86 kind,
87 node_kind_version,
88 schema_latest_kind_version,
89 });
90 }
91
92 pub(in crate::schema) fn push_error(
93 &mut self,
94 node: NodeId,
95 kind: NodeKindKey,
96 from: u32,
97 to: u32,
98 message: impl Into<String>,
99 ) {
100 self.errors.push(NodeMigrationErrorEntry {
101 node,
102 kind,
103 from,
104 to,
105 message: message.into(),
106 });
107 }
108}
109
110#[derive(Debug, Clone)]
111pub struct NodeMigrationUpgraded {
112 pub node: NodeId,
113 pub kind: NodeKindKey,
114 pub from: u32,
115 pub to: u32,
116}
117
118#[derive(Debug, Clone)]
119pub struct NodeMigrationMissingSchema {
120 pub node: NodeId,
121 pub kind: NodeKindKey,
122}
123
124#[derive(Debug, Clone)]
125pub struct NodeMigrationMissingMigrator {
126 pub node: NodeId,
127 pub kind: NodeKindKey,
128 pub from: u32,
129 pub to: u32,
130}
131
132#[derive(Debug, Clone)]
133pub struct NodeMigrationNewerThanSchema {
134 pub node: NodeId,
135 pub kind: NodeKindKey,
136 pub node_kind_version: u32,
137 pub schema_latest_kind_version: u32,
138}
139
140#[derive(Debug, Clone)]
141pub struct NodeMigrationErrorEntry {
142 pub node: NodeId,
143 pub kind: NodeKindKey,
144 pub from: u32,
145 pub to: u32,
146 pub message: String,
147}
148
149#[derive(Debug, Clone)]
150pub struct MigrateNodesPlan {
151 pub tx: GraphTransaction,
152 pub report: MigrateNodesReport,
153}
154
155impl MigrateNodesPlan {
156 pub(in crate::schema) fn from_parts(tx: GraphTransaction, report: MigrateNodesReport) -> Self {
157 Self { tx, report }
158 }
159
160 pub fn transaction(&self) -> &GraphTransaction {
161 &self.tx
162 }
163
164 pub fn report(&self) -> &MigrateNodesReport {
165 &self.report
166 }
167
168 pub fn into_parts(self) -> (GraphTransaction, MigrateNodesReport) {
169 (self.tx, self.report)
170 }
171}