1use serde::{Deserialize, Serialize};
10use uqa_core::{
11 memory::{Produced, ProductionControl},
12 ValueRetentionError,
13};
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct CreateEnum {
18 pub name: String,
20 pub labels: Vec<String>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct AlterEnum {
26 pub name: String,
27 pub action: AlterEnumAction,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub enum AlterEnumAction {
32 AddValue {
33 label: String,
34 if_not_exists: bool,
35 neighbor: Option<EnumNeighbor>,
36 },
37 RenameValue {
38 old: String,
39 new: String,
40 },
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct EnumNeighbor {
46 pub label: String,
47 pub after: bool,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct EnumTypeReference {
53 pub schema: String,
54 pub name: String,
55 pub oid: u32,
56 pub array_oid: u32,
57}
58
59impl PartialEq for EnumTypeReference {
60 fn eq(&self, other: &Self) -> bool {
61 self.oid == other.oid
62 }
63}
64
65impl Eq for EnumTypeReference {}
66
67impl EnumTypeReference {
68 pub fn clone_with_control(
70 &self,
71 control: &ProductionControl<'_>,
72 ) -> Result<Produced<Self>, ValueRetentionError> {
73 let schema = control.copy_text(&self.schema)?;
74 let name = control.copy_text(&self.name)?;
75 let (schema, schema_memory) = schema.into_parts();
76 let (name, name_memory) = name.into_parts();
77 control.finish(
78 Self {
79 schema,
80 name,
81 oid: self.oid,
82 array_oid: self.array_oid,
83 },
84 control.combine(schema_memory, name_memory),
85 )
86 }
87}