pgevolve_core/diff/
owner_op.rs1use serde::{Deserialize, Serialize};
4
5use crate::identifier::{Identifier, QualifiedName};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum OwnerObjectKind {
12 Schema,
14 Sequence,
16 Table,
18 View,
20 MaterializedView,
22 Function,
24 Procedure,
26 UserType,
28 Publication,
30}
31
32impl OwnerObjectKind {
33 #[must_use]
35 pub const fn sql_keyword(self) -> &'static str {
36 match self {
37 Self::Schema => "SCHEMA",
38 Self::Sequence => "SEQUENCE",
39 Self::Table => "TABLE",
40 Self::View => "VIEW",
41 Self::MaterializedView => "MATERIALIZED VIEW",
42 Self::Function => "FUNCTION",
43 Self::Procedure => "PROCEDURE",
44 Self::UserType => "TYPE",
45 Self::Publication => "PUBLICATION",
46 }
47 }
48}
49
50#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53pub struct AlterObjectOwner {
54 pub kind: OwnerObjectKind,
56 pub qname: QualifiedName,
58 #[serde(default)]
61 pub signature: String,
62 pub from: Identifier,
65 pub to: Identifier,
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn sql_keywords_match_pg() {
75 assert_eq!(OwnerObjectKind::Schema.sql_keyword(), "SCHEMA");
76 assert_eq!(OwnerObjectKind::Sequence.sql_keyword(), "SEQUENCE");
77 assert_eq!(OwnerObjectKind::Table.sql_keyword(), "TABLE");
78 assert_eq!(OwnerObjectKind::View.sql_keyword(), "VIEW");
79 assert_eq!(
80 OwnerObjectKind::MaterializedView.sql_keyword(),
81 "MATERIALIZED VIEW"
82 );
83 assert_eq!(OwnerObjectKind::Function.sql_keyword(), "FUNCTION");
84 assert_eq!(OwnerObjectKind::Procedure.sql_keyword(), "PROCEDURE");
85 assert_eq!(OwnerObjectKind::UserType.sql_keyword(), "TYPE");
86 assert_eq!(OwnerObjectKind::Publication.sql_keyword(), "PUBLICATION");
87 }
88}