Fire BEFORE ROW triggers for a DELETE operation. BEFORE DELETE triggers cannot modify the row (there is no NEW). They can only validate and reject via RAISE EXCEPTION, or execute side-effect DML. If a trigger raises an exception, the DELETE is aborted.
(
state: &SharedState,
identity: &AuthenticatedIdentity,
tenant_id: TenantId,
collection: &str,
old_fields: &HashMap<String, nodedb_types::Value>,
cascade_depth: u32,
)
| 125 | /// |
| 126 | /// If a trigger raises an exception, the DELETE is aborted. |
| 127 | pub async fn fire_before_delete( |
| 128 | state: &SharedState, |
| 129 | identity: &AuthenticatedIdentity, |
| 130 | tenant_id: TenantId, |
| 131 | collection: &str, |
| 132 | old_fields: &HashMap<String, nodedb_types::Value>, |
| 133 | cascade_depth: u32, |
| 134 | ) -> crate::Result<()> { |
| 135 | let triggers = |
| 136 | state |
| 137 | .trigger_registry |
| 138 | .get_matching(tenant_id.as_u64(), collection, DmlEvent::Delete); |
| 139 | |
| 140 | let before_triggers: Vec<_> = triggers |
| 141 | .into_iter() |
| 142 | .filter(|t| t.timing == TriggerTiming::Before) |
| 143 | .collect(); |
| 144 | |
| 145 | if before_triggers.is_empty() { |
| 146 | return Ok(()); |
| 147 | } |
| 148 | |
| 149 | check_cascade_depth(cascade_depth, collection)?; |
| 150 | |
| 151 | let bindings = RowBindings::before_delete(collection, old_fields.clone()); |
| 152 | |
| 153 | fire_triggers( |
| 154 | state, |
| 155 | identity, |
| 156 | tenant_id, |
| 157 | collection, |
| 158 | &before_triggers, |
| 159 | &bindings, |
| 160 | cascade_depth, |
| 161 | ) |
| 162 | .await |
| 163 | } |
no test coverage detected