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