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	dictionary::DictionaryDef,
13	flow::FlowDef,
14	handler::HandlerDef,
15	migration::{MigrationDef, MigrationEvent},
16	namespace::Namespace,
17	policy::PolicyDef,
18	procedure::ProcedureDef,
19	ringbuffer::RingBufferDef,
20	series::SeriesDef,
21	subscription::SubscriptionDef,
22	sumtype::SumTypeDef,
23	table::TableDef,
24	test::TestDef,
25	user::{RoleDef, UserDef, UserRoleDef},
26	user_authentication::UserAuthenticationDef,
27	view::ViewDef,
28};
29
30/// Trait for tracking table definition changes during a transaction.
31pub trait CatalogTrackTableChangeOperations {
32	fn track_table_def_created(&mut self, table: TableDef) -> Result<()>;
33
34	fn track_table_def_updated(&mut self, pre: TableDef, post: TableDef) -> Result<()>;
35
36	fn track_table_def_deleted(&mut self, table: TableDef) -> Result<()>;
37}
38
39/// Trait for tracking namespace definition changes during a transaction.
40pub trait CatalogTrackNamespaceChangeOperations {
41	fn track_namespace_created(&mut self, namespace: Namespace) -> Result<()>;
42
43	fn track_namespace_updated(&mut self, pre: Namespace, post: Namespace) -> Result<()>;
44
45	fn track_namespace_deleted(&mut self, namespace: Namespace) -> Result<()>;
46}
47
48/// Trait for tracking flow definition changes during a transaction.
49pub trait CatalogTrackFlowChangeOperations {
50	fn track_flow_def_created(&mut self, flow: FlowDef) -> Result<()>;
51
52	fn track_flow_def_updated(&mut self, pre: FlowDef, post: FlowDef) -> Result<()>;
53
54	fn track_flow_def_deleted(&mut self, flow: FlowDef) -> Result<()>;
55}
56
57/// Trait for tracking view definition changes during a transaction.
58pub trait CatalogTrackViewChangeOperations {
59	fn track_view_def_created(&mut self, view: ViewDef) -> Result<()>;
60
61	fn track_view_def_updated(&mut self, pre: ViewDef, post: ViewDef) -> Result<()>;
62
63	fn track_view_def_deleted(&mut self, view: ViewDef) -> Result<()>;
64}
65
66/// Trait for tracking dictionary definition changes during a transaction.
67pub trait CatalogTrackDictionaryChangeOperations {
68	fn track_dictionary_def_created(&mut self, dictionary: DictionaryDef) -> Result<()>;
69
70	fn track_dictionary_def_updated(&mut self, pre: DictionaryDef, post: DictionaryDef) -> Result<()>;
71
72	fn track_dictionary_def_deleted(&mut self, dictionary: DictionaryDef) -> Result<()>;
73}
74
75/// Trait for tracking series definition changes during a transaction.
76pub trait CatalogTrackSeriesChangeOperations {
77	fn track_series_def_created(&mut self, series: SeriesDef) -> Result<()>;
78
79	fn track_series_def_updated(&mut self, pre: SeriesDef, post: SeriesDef) -> Result<()>;
80
81	fn track_series_def_deleted(&mut self, series: SeriesDef) -> Result<()>;
82}
83
84/// Trait for tracking ringbuffer definition changes during a transaction.
85pub trait CatalogTrackRingBufferChangeOperations {
86	fn track_ringbuffer_def_created(&mut self, ringbuffer: RingBufferDef) -> Result<()>;
87
88	fn track_ringbuffer_def_updated(&mut self, pre: RingBufferDef, post: RingBufferDef) -> Result<()>;
89
90	fn track_ringbuffer_def_deleted(&mut self, ringbuffer: RingBufferDef) -> Result<()>;
91}
92
93/// Trait for tracking subscription definition changes during a transaction.
94pub trait CatalogTrackSubscriptionChangeOperations {
95	fn track_subscription_def_created(&mut self, subscription: SubscriptionDef) -> Result<()>;
96
97	fn track_subscription_def_updated(&mut self, pre: SubscriptionDef, post: SubscriptionDef) -> Result<()>;
98
99	fn track_subscription_def_deleted(&mut self, subscription: SubscriptionDef) -> Result<()>;
100}
101
102/// Trait for tracking sum type definition changes during a transaction.
103pub trait CatalogTrackSumTypeChangeOperations {
104	fn track_sumtype_def_created(&mut self, sumtype: SumTypeDef) -> Result<()>;
105
106	fn track_sumtype_def_updated(&mut self, pre: SumTypeDef, post: SumTypeDef) -> Result<()>;
107
108	fn track_sumtype_def_deleted(&mut self, sumtype: SumTypeDef) -> Result<()>;
109}
110
111/// Trait for tracking procedure definition changes during a transaction.
112pub trait CatalogTrackProcedureChangeOperations {
113	fn track_procedure_def_created(&mut self, procedure: ProcedureDef) -> Result<()>;
114
115	fn track_procedure_def_updated(&mut self, pre: ProcedureDef, post: ProcedureDef) -> Result<()>;
116
117	fn track_procedure_def_deleted(&mut self, procedure: ProcedureDef) -> Result<()>;
118}
119
120/// Trait for tracking test definition changes during a transaction.
121pub trait CatalogTrackTestChangeOperations {
122	fn track_test_def_created(&mut self, test: TestDef) -> Result<()>;
123
124	fn track_test_def_deleted(&mut self, test: TestDef) -> Result<()>;
125}
126
127/// Trait for tracking handler definition changes during a transaction.
128pub trait CatalogTrackHandlerChangeOperations {
129	fn track_handler_def_created(&mut self, handler: HandlerDef) -> Result<()>;
130
131	fn track_handler_def_deleted(&mut self, handler: HandlerDef) -> Result<()>;
132}
133
134/// Trait for tracking user definition changes during a transaction.
135pub trait CatalogTrackUserChangeOperations {
136	fn track_user_def_created(&mut self, user: UserDef) -> Result<()>;
137
138	fn track_user_def_updated(&mut self, pre: UserDef, post: UserDef) -> Result<()>;
139
140	fn track_user_def_deleted(&mut self, user: UserDef) -> Result<()>;
141}
142
143/// Trait for tracking role definition changes during a transaction.
144pub trait CatalogTrackRoleChangeOperations {
145	fn track_role_def_created(&mut self, role: RoleDef) -> Result<()>;
146
147	fn track_role_def_updated(&mut self, pre: RoleDef, post: RoleDef) -> Result<()>;
148
149	fn track_role_def_deleted(&mut self, role: RoleDef) -> Result<()>;
150}
151
152/// Trait for tracking user-role definition changes during a transaction.
153pub trait CatalogTrackUserRoleChangeOperations {
154	fn track_user_role_def_created(&mut self, user_role: UserRoleDef) -> Result<()>;
155
156	fn track_user_role_def_deleted(&mut self, user_role: UserRoleDef) -> Result<()>;
157}
158
159/// Trait for tracking policy definition changes during a transaction.
160pub trait CatalogTrackPolicyChangeOperations {
161	fn track_policy_def_created(&mut self, policy: PolicyDef) -> Result<()>;
162
163	fn track_policy_def_updated(&mut self, pre: PolicyDef, post: PolicyDef) -> Result<()>;
164
165	fn track_policy_def_deleted(&mut self, policy: PolicyDef) -> Result<()>;
166}
167
168/// Trait for tracking migration definition changes during a transaction.
169pub trait CatalogTrackMigrationChangeOperations {
170	fn track_migration_def_created(&mut self, migration: MigrationDef) -> Result<()>;
171
172	fn track_migration_def_deleted(&mut self, migration: MigrationDef) -> Result<()>;
173}
174
175/// Trait for tracking migration event changes during a transaction.
176pub trait CatalogTrackMigrationEventChangeOperations {
177	fn track_migration_event_created(&mut self, event: MigrationEvent) -> Result<()>;
178}
179
180/// Trait for tracking user authentication definition changes during a transaction.
181pub trait CatalogTrackUserAuthenticationChangeOperations {
182	fn track_user_authentication_def_created(&mut self, auth: UserAuthenticationDef) -> Result<()>;
183
184	fn track_user_authentication_def_deleted(&mut self, auth: UserAuthenticationDef) -> Result<()>;
185}
186
187/// Umbrella trait for all catalog change tracking operations.
188pub trait CatalogTrackChangeOperations:
189	CatalogTrackDictionaryChangeOperations
190	+ CatalogTrackFlowChangeOperations
191	+ CatalogTrackHandlerChangeOperations
192	+ CatalogTrackMigrationChangeOperations
193	+ CatalogTrackMigrationEventChangeOperations
194	+ CatalogTrackNamespaceChangeOperations
195	+ CatalogTrackProcedureChangeOperations
196	+ CatalogTrackRingBufferChangeOperations
197	+ CatalogTrackRoleChangeOperations
198	+ CatalogTrackPolicyChangeOperations
199	+ CatalogTrackSeriesChangeOperations
200	+ CatalogTrackSubscriptionChangeOperations
201	+ CatalogTrackSumTypeChangeOperations
202	+ CatalogTrackTableChangeOperations
203	+ CatalogTrackTestChangeOperations
204	+ CatalogTrackUserAuthenticationChangeOperations
205	+ CatalogTrackUserChangeOperations
206	+ CatalogTrackUserRoleChangeOperations
207	+ CatalogTrackViewChangeOperations
208{
209}