reifydb_catalog/store/flow/
delete.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use reifydb_core::interface::{CommandTransaction, FlowId, FlowKey, NamespaceFlowKey};
5
6use crate::CatalogStore;
7
8impl CatalogStore {
9	pub async fn delete_flow(txn: &mut impl CommandTransaction, flow_id: FlowId) -> crate::Result<()> {
10		// Get the flow to find namespace for index deletion
11		let flow_def = CatalogStore::find_flow(txn, flow_id).await?;
12
13		if let Some(flow) = flow_def {
14			// Step 1: Delete all nodes for this flow
15			let nodes = CatalogStore::list_flow_nodes_by_flow(txn, flow_id).await?;
16			for node in nodes {
17				CatalogStore::delete_flow_node(txn, node.id).await?;
18			}
19
20			// Step 2: Delete all edges for this flow
21			let edges = CatalogStore::list_flow_edges_by_flow(txn, flow_id).await?;
22			for edge in edges {
23				CatalogStore::delete_flow_edge(txn, edge.id).await?;
24			}
25
26			// Step 3: Delete from namespace index
27			txn.remove(&NamespaceFlowKey::encoded(flow.namespace, flow_id)).await?;
28
29			// Step 4: Delete from main flow table
30			txn.remove(&FlowKey::encoded(flow_id)).await?;
31		}
32
33		Ok(())
34	}
35}