pgmt 0.5.0

PostgreSQL migration tool that keeps your schema files as the source of truth
Documentation
//! View operations for schema migrations

use super::OperationKind;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ViewOption {
    SecurityInvoker,
    SecurityBarrier,
}

impl ViewOption {
    pub fn as_str(&self) -> &'static str {
        match self {
            ViewOption::SecurityInvoker => "security_invoker",
            ViewOption::SecurityBarrier => "security_barrier",
        }
    }
}

#[derive(Debug, Clone)]
pub enum ViewOperation {
    Create {
        schema: String,
        name: String,
        definition: String,
        security_invoker: bool,
        security_barrier: bool,
    },
    Drop {
        schema: String,
        name: String,
    },
    Replace {
        schema: String,
        name: String,
        definition: String,
        security_invoker: bool,
        security_barrier: bool,
    },
    SetOption {
        schema: String,
        name: String,
        option: ViewOption,
        enabled: bool,
    },
}

impl ViewOperation {
    pub fn operation_kind(&self) -> OperationKind {
        match self {
            Self::Create { .. } => OperationKind::Create,
            Self::Drop { .. } => OperationKind::Drop,
            Self::Replace { .. } => OperationKind::Alter,
            Self::SetOption { .. } => OperationKind::Alter,
        }
    }
}