uqa_sql/catalog/events/
restoration.rs1use super::definition::EventAnalysisContext;
9use crate::{ast::CreateTrigger, catalog::resolution::RelationLookupMode};
10
11pub fn restore_rule_expressions(
13 rule: &mut super::StoredRule,
14 routines: &dyn crate::FunctionTypeResolver,
15) -> Result<bool, crate::SQLError> {
16 let mut changed = rule.definition.condition.is_some() && rule.bound_condition_plan().is_none();
17 if let Some(condition) = &mut rule.definition.condition {
18 changed |= condition.upgrade_legacy_serialized_dispatches();
19 changed |= crate::binding::legacy_patterns::restore_expression(condition, routines)
20 .map_err(crate::SQLError::Internal)?;
21 }
22 if let Some(condition) = &mut rule.condition_plan {
23 changed |= crate::binding::legacy_patterns::restore_expression_plan(condition, routines);
24 changed |= condition.upgrade_legacy_range_predicates()?;
25 }
26 for action in &mut rule.definition.actions {
27 changed |= action.upgrade_legacy_serialized_dispatches();
28 changed |= crate::binding::legacy_patterns::restore_statement(action, routines)?;
29 }
30 Ok(changed)
31}
32
33pub fn trigger_function_object_id(
34 context: &EventAnalysisContext<'_>,
35 definition: &CreateTrigger,
36) -> Result<[u8; 16], String> {
37 context
38 .resolve_trigger_function(&definition.function, RelationLookupMode::Bound)
39 .map_err(|error| format!("restore trigger function identity: {error}"))?
40 .def
41 .object_id
42 .ok_or_else(|| {
43 format!(
44 "restore trigger catalog: function `{}` has no object identity",
45 definition.function
46 )
47 })
48}