Skip to main content

reifydb_core/interface/catalog/
change.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Catalog change tracking traits.
5//!
6//! These traits are used by command transactions to track changes to catalog entities
7//! during a transaction, allowing for proper transactional semantics and rollback.
8
9use reifydb_type::Result;
10
11use crate::{
12	interface::catalog::{
13		authentication::Authentication,
14		binding::Binding,
15		config::Config,
16		dictionary::Dictionary,
17		flow::Flow,
18		handler::Handler,
19		identity::{GrantedRole, Identity, Role},
20		migration::{Migration, MigrationEvent},
21		namespace::Namespace,
22		policy::Policy,
23		procedure::Procedure,
24		ringbuffer::RingBuffer,
25		series::Series,
26		shape::ShapeId,
27		sink::Sink,
28		source::Source,
29		sumtype::SumType,
30		table::Table,
31		test::Test,
32		view::View,
33	},
34	row::RowTtl,
35};
36
37/// Trait for tracking configuration changes during a transaction.
38pub trait CatalogTrackConfigChangeOperations {
39	fn track_config_set(&mut self, pre: Config, post: Config) -> Result<()>;
40}
41
42/// Trait for tracking table definition changes during a transaction.
43pub trait CatalogTrackTableChangeOperations {
44	fn track_table_created(&mut self, table: Table) -> Result<()>;
45
46	fn track_table_updated(&mut self, pre: Table, post: Table) -> Result<()>;
47
48	fn track_table_deleted(&mut self, table: Table) -> Result<()>;
49}
50
51/// Trait for tracking namespace definition changes during a transaction.
52pub trait CatalogTrackNamespaceChangeOperations {
53	fn track_namespace_created(&mut self, namespace: Namespace) -> Result<()>;
54
55	fn track_namespace_updated(&mut self, pre: Namespace, post: Namespace) -> Result<()>;
56
57	fn track_namespace_deleted(&mut self, namespace: Namespace) -> Result<()>;
58}
59
60/// Trait for tracking flow definition changes during a transaction.
61pub trait CatalogTrackFlowChangeOperations {
62	fn track_flow_created(&mut self, flow: Flow) -> Result<()>;
63
64	fn track_flow_updated(&mut self, pre: Flow, post: Flow) -> Result<()>;
65
66	fn track_flow_deleted(&mut self, flow: Flow) -> Result<()>;
67}
68
69/// Trait for tracking view definition changes during a transaction.
70pub trait CatalogTrackViewChangeOperations {
71	fn track_view_created(&mut self, view: View) -> Result<()>;
72
73	fn track_view_updated(&mut self, pre: View, post: View) -> Result<()>;
74
75	fn track_view_deleted(&mut self, view: View) -> Result<()>;
76}
77
78/// Trait for tracking dictionary definition changes during a transaction.
79pub trait CatalogTrackDictionaryChangeOperations {
80	fn track_dictionary_created(&mut self, dictionary: Dictionary) -> Result<()>;
81
82	fn track_dictionary_updated(&mut self, pre: Dictionary, post: Dictionary) -> Result<()>;
83
84	fn track_dictionary_deleted(&mut self, dictionary: Dictionary) -> Result<()>;
85}
86
87/// Trait for tracking series definition changes during a transaction.
88pub trait CatalogTrackSeriesChangeOperations {
89	fn track_series_created(&mut self, series: Series) -> Result<()>;
90
91	fn track_series_updated(&mut self, pre: Series, post: Series) -> Result<()>;
92
93	fn track_series_deleted(&mut self, series: Series) -> Result<()>;
94}
95
96/// Trait for tracking ringbuffer definition changes during a transaction.
97pub trait CatalogTrackRingBufferChangeOperations {
98	fn track_ringbuffer_created(&mut self, ringbuffer: RingBuffer) -> Result<()>;
99
100	fn track_ringbuffer_updated(&mut self, pre: RingBuffer, post: RingBuffer) -> Result<()>;
101
102	fn track_ringbuffer_deleted(&mut self, ringbuffer: RingBuffer) -> Result<()>;
103}
104
105/// Trait for tracking sum type definition changes during a transaction.
106pub trait CatalogTrackSumTypeChangeOperations {
107	fn track_sumtype_created(&mut self, sumtype: SumType) -> Result<()>;
108
109	fn track_sumtype_updated(&mut self, pre: SumType, post: SumType) -> Result<()>;
110
111	fn track_sumtype_deleted(&mut self, sumtype: SumType) -> Result<()>;
112}
113
114/// Trait for tracking procedure definition changes during a transaction.
115pub trait CatalogTrackProcedureChangeOperations {
116	fn track_procedure_created(&mut self, procedure: Procedure) -> Result<()>;
117
118	fn track_procedure_updated(&mut self, pre: Procedure, post: Procedure) -> Result<()>;
119
120	fn track_procedure_deleted(&mut self, procedure: Procedure) -> Result<()>;
121}
122
123/// Trait for tracking test definition changes during a transaction.
124pub trait CatalogTrackTestChangeOperations {
125	fn track_test_created(&mut self, test: Test) -> Result<()>;
126
127	fn track_test_deleted(&mut self, test: Test) -> Result<()>;
128}
129
130/// Trait for tracking handler definition changes during a transaction.
131pub trait CatalogTrackHandlerChangeOperations {
132	fn track_handler_created(&mut self, handler: Handler) -> Result<()>;
133
134	fn track_handler_deleted(&mut self, handler: Handler) -> Result<()>;
135}
136
137/// Trait for tracking identity definition changes during a transaction.
138pub trait CatalogTrackIdentityChangeOperations {
139	fn track_identity_created(&mut self, identity: Identity) -> Result<()>;
140
141	fn track_identity_updated(&mut self, pre: Identity, post: Identity) -> Result<()>;
142
143	fn track_identity_deleted(&mut self, identity: Identity) -> Result<()>;
144}
145
146/// Trait for tracking role definition changes during a transaction.
147pub trait CatalogTrackRoleChangeOperations {
148	fn track_role_created(&mut self, role: Role) -> Result<()>;
149
150	fn track_role_updated(&mut self, pre: Role, post: Role) -> Result<()>;
151
152	fn track_role_deleted(&mut self, role: Role) -> Result<()>;
153}
154
155/// Trait for tracking granted-role changes during a transaction.
156pub trait CatalogTrackGrantedRoleChangeOperations {
157	fn track_granted_role_created(&mut self, granted_role: GrantedRole) -> Result<()>;
158
159	fn track_granted_role_deleted(&mut self, granted_role: GrantedRole) -> Result<()>;
160}
161
162/// Trait for tracking policy definition changes during a transaction.
163pub trait CatalogTrackPolicyChangeOperations {
164	fn track_policy_created(&mut self, policy: Policy) -> Result<()>;
165
166	fn track_policy_updated(&mut self, pre: Policy, post: Policy) -> Result<()>;
167
168	fn track_policy_deleted(&mut self, policy: Policy) -> Result<()>;
169}
170
171/// Trait for tracking migration definition changes during a transaction.
172pub trait CatalogTrackMigrationChangeOperations {
173	fn track_migration_created(&mut self, migration: Migration) -> Result<()>;
174
175	fn track_migration_deleted(&mut self, migration: Migration) -> Result<()>;
176}
177
178/// Trait for tracking migration event changes during a transaction.
179pub trait CatalogTrackMigrationEventChangeOperations {
180	fn track_migration_event_created(&mut self, event: MigrationEvent) -> Result<()>;
181}
182
183/// Trait for tracking authentication definition changes during a transaction.
184pub trait CatalogTrackAuthenticationChangeOperations {
185	fn track_authentication_created(&mut self, auth: Authentication) -> Result<()>;
186
187	fn track_authentication_deleted(&mut self, auth: Authentication) -> Result<()>;
188}
189
190/// Trait for tracking source definition changes during a transaction.
191pub trait CatalogTrackSourceChangeOperations {
192	fn track_source_created(&mut self, source: Source) -> Result<()>;
193
194	fn track_source_deleted(&mut self, source: Source) -> Result<()>;
195}
196
197/// Trait for tracking binding definition changes during a transaction.
198pub trait CatalogTrackBindingChangeOperations {
199	fn track_binding_created(&mut self, binding: Binding) -> Result<()>;
200
201	fn track_binding_deleted(&mut self, binding: Binding) -> Result<()>;
202}
203
204/// Trait for tracking sink definition changes during a transaction.
205pub trait CatalogTrackSinkChangeOperations {
206	fn track_sink_created(&mut self, sink: Sink) -> Result<()>;
207
208	fn track_sink_deleted(&mut self, sink: Sink) -> Result<()>;
209}
210
211/// Trait for tracking row TTL changes during a transaction.
212pub trait CatalogTrackRowTtlChangeOperations {
213	fn track_row_ttl_created(&mut self, shape: ShapeId, ttl: RowTtl) -> Result<()>;
214
215	fn track_row_ttl_updated(&mut self, shape: ShapeId, pre: RowTtl, post: RowTtl) -> Result<()>;
216
217	fn track_row_ttl_deleted(&mut self, shape: ShapeId, ttl: RowTtl) -> Result<()>;
218}
219
220/// Umbrella trait for all catalog change tracking operations.
221pub trait CatalogTrackChangeOperations:
222	CatalogTrackBindingChangeOperations
223	+ CatalogTrackDictionaryChangeOperations
224	+ CatalogTrackFlowChangeOperations
225	+ CatalogTrackHandlerChangeOperations
226	+ CatalogTrackMigrationChangeOperations
227	+ CatalogTrackMigrationEventChangeOperations
228	+ CatalogTrackNamespaceChangeOperations
229	+ CatalogTrackProcedureChangeOperations
230	+ CatalogTrackRingBufferChangeOperations
231	+ CatalogTrackRoleChangeOperations
232	+ CatalogTrackPolicyChangeOperations
233	+ CatalogTrackSeriesChangeOperations
234	+ CatalogTrackSinkChangeOperations
235	+ CatalogTrackSourceChangeOperations
236	+ CatalogTrackSumTypeChangeOperations
237	+ CatalogTrackTableChangeOperations
238	+ CatalogTrackTestChangeOperations
239	+ CatalogTrackAuthenticationChangeOperations
240	+ CatalogTrackIdentityChangeOperations
241	+ CatalogTrackGrantedRoleChangeOperations
242	+ CatalogTrackViewChangeOperations
243	+ CatalogTrackConfigChangeOperations
244	+ CatalogTrackRowTtlChangeOperations
245{
246}