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