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