Skip to main content

safe_migrate/model/
trigger.rs

1use crate::ast::identifiers::ObjectId;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
5pub enum TriggerEnableMode {
6    Disabled,
7    #[default]
8    Origin,
9    Replica,
10    Always,
11}
12
13impl TriggerEnableMode {
14    pub fn from_pg_code(code: &str) -> Option<Self> {
15        match code {
16            "D" => Some(Self::Disabled),
17            "O" => Some(Self::Origin),
18            "R" => Some(Self::Replica),
19            "A" => Some(Self::Always),
20            _ => None,
21        }
22    }
23}
24
25#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26pub struct TriggerState {
27    /// PostgreSQL trigger names are scoped to their table, not their schema.
28    /// `id` is an internal composite key; retain the display name separately
29    /// for matching ALTER/DROP TRIGGER statements and diagnostics.
30    pub name: String,
31    pub id: ObjectId,
32    pub table_id: ObjectId,
33    pub enabled_mode: TriggerEnableMode,
34    pub generation: u64,
35}
36
37#[derive(Debug, Clone, PartialEq)]
38pub enum TriggerOverlay {
39    Present(TriggerState),
40    Dropped,
41}