Skip to main content

uqa_sql/ast/
type_lifecycle.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! `ALTER TYPE | DOMAIN ... RENAME TO | SET SCHEMA | OWNER TO`.
8
9use serde::{Deserialize, Serialize};
10
11use super::RoleSpecification;
12
13/// The keyword that named the target. `DOMAIN` statements reject types that are not domains.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15pub enum TypeObjectKind {
16    Type,
17    Domain,
18}
19
20/// A description on a type identity; an empty or NULL description removes it.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct CommentType {
23    pub kind: TypeObjectKind,
24    pub name: String,
25    pub description: Option<String>,
26}
27
28/// One `ALTER TYPE` or `ALTER DOMAIN` lifecycle change of a user-defined type and its generated array type.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct AlterTypeObject {
31    pub kind: TypeObjectKind,
32    /// Rendered, possibly qualified type name as written.
33    pub name: String,
34    pub action: AlterTypeObjectAction,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub enum AlterTypeObjectAction {
39    /// The new unqualified name.
40    RenameTo(String),
41    /// The destination schema.
42    SetSchema(String),
43    OwnerTo(RoleSpecification),
44    /// Rename an attribute without changing its type or attribute number.
45    RenameAttribute {
46        from: String,
47        to: String,
48    },
49    /// Append attributes to a standalone composite relation in written order.
50    AddAttributes(Vec<super::CompositeAttributeAddition>),
51    /// `PostgreSQL` prepares types against the original descriptor, then executes DROP, TYPE and ADD groups in order.
52    AlterAttributes {
53        removals: Vec<super::CompositeAttributeRemoval>,
54        #[serde(default)]
55        type_changes: Vec<super::CompositeAttributeDefinition>,
56        additions: Vec<super::CompositeAttributeAddition>,
57    },
58}