Skip to main content

toasty_sql/stmt/
alter_type.rs

1use super::Statement;
2
3use toasty_core::schema::db::EnumVariant;
4
5/// An `ALTER TYPE ... ADD VALUE '...'` statement.
6///
7/// PostgreSQL requires a separate `ALTER TYPE` for each new variant. This
8/// statement represents adding a single variant to an existing named enum type.
9#[derive(Debug, Clone)]
10pub struct AlterType {
11    /// The name of the enum type to alter.
12    pub type_name: String,
13    /// The new variant to add.
14    pub variant: EnumVariant,
15}
16
17impl Statement {
18    /// Creates an `ALTER TYPE <name> ADD VALUE '<variant>'` statement.
19    pub fn alter_type_add_value(type_name: &str, variant: &EnumVariant) -> Self {
20        AlterType {
21            type_name: type_name.to_string(),
22            variant: variant.clone(),
23        }
24        .into()
25    }
26}
27
28impl From<AlterType> for Statement {
29    fn from(value: AlterType) -> Self {
30        Self::AlterType(value)
31    }
32}