Skip to main content

safe_migrate/model/
function.rs

1use crate::ast::identifiers::ObjectId;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub enum Volatility {
6    Volatile,
7    Stable,
8    Immutable,
9}
10
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12pub enum SecurityMode {
13    Invoker,
14    Definer,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
18pub enum RoutineKind {
19    #[default]
20    Function,
21    Procedure,
22    Aggregate,
23    Window,
24}
25
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
27pub struct FunctionState {
28    pub id: ObjectId,
29    pub routine_kind: RoutineKind,
30    pub arg_types: Vec<String>,
31    /// Derived from `arg_types` when a cache enters analysis. Keeping it out
32    /// of the cache preserves the stable binary representation.
33    #[serde(skip)]
34    pub arg_type_ids: Vec<Option<ObjectId>>,
35    pub return_type: String,
36    /// Derived from `return_type` when a cache enters analysis. Keeping it out
37    /// of the cache preserves the stable binary representation.
38    #[serde(skip)]
39    pub return_type_id: Option<ObjectId>,
40    pub volatility: Volatility,
41    pub language: String,
42    pub security: SecurityMode,
43}
44
45#[derive(Debug, Clone, PartialEq)]
46#[allow(clippy::large_enum_variant)] // Overlay transitions stay allocation-free in the hot state path.
47pub enum FunctionOverlay {
48    Present(FunctionState),
49    Dropped,
50}