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 Subscription,
32 Statistic,
34}
35
36impl OwnerObjectKind {
37 #[must_use]
39 pub const fn sql_keyword(self) -> &'static str {
40 match self {
41 Self::Schema => "SCHEMA",
42 Self::Sequence => "SEQUENCE",
43 Self::Table => "TABLE",
44 Self::View => "VIEW",
45 Self::MaterializedView => "MATERIALIZED VIEW",
46 Self::Function => "FUNCTION",
47 Self::Procedure => "PROCEDURE",
48 Self::UserType => "TYPE",
49 Self::Publication => "PUBLICATION",
50 Self::Subscription => "SUBSCRIPTION",
51 Self::Statistic => "STATISTICS",
52 }
53 }
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59pub struct AlterObjectOwner {
60 pub kind: OwnerObjectKind,
62 pub qname: QualifiedName,
64 #[serde(default)]
67 pub signature: String,
68 pub from: Identifier,
71 pub to: Identifier,
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn sql_keywords_match_pg() {
81 assert_eq!(OwnerObjectKind::Schema.sql_keyword(), "SCHEMA");
82 assert_eq!(OwnerObjectKind::Sequence.sql_keyword(), "SEQUENCE");
83 assert_eq!(OwnerObjectKind::Table.sql_keyword(), "TABLE");
84 assert_eq!(OwnerObjectKind::View.sql_keyword(), "VIEW");
85 assert_eq!(
86 OwnerObjectKind::MaterializedView.sql_keyword(),
87 "MATERIALIZED VIEW"
88 );
89 assert_eq!(OwnerObjectKind::Function.sql_keyword(), "FUNCTION");
90 assert_eq!(OwnerObjectKind::Procedure.sql_keyword(), "PROCEDURE");
91 assert_eq!(OwnerObjectKind::UserType.sql_keyword(), "TYPE");
92 assert_eq!(OwnerObjectKind::Publication.sql_keyword(), "PUBLICATION");
93 assert_eq!(OwnerObjectKind::Subscription.sql_keyword(), "SUBSCRIPTION");
94 assert_eq!(OwnerObjectKind::Statistic.sql_keyword(), "STATISTICS");
95 }
96}