@@ -640,6 +640,95 @@ impl fmt::Display for AlterIndexOperation {
640640 }
641641}
642642
643+ /// An `ALTER TYPE` statement (`Statement::AlterType`)
644+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
645+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
646+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
647+ pub struct AlterType {
648+ pub name : ObjectName ,
649+ pub operation : AlterTypeOperation ,
650+ }
651+
652+ /// An [AlterType] operation
653+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
654+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
655+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
656+ pub enum AlterTypeOperation {
657+ Rename ( AlterTypeRename ) ,
658+ AddValue ( AlterTypeAddValue ) ,
659+ RenameValue ( AlterTypeRenameValue ) ,
660+ }
661+
662+ /// See [AlterTypeOperation::Rename]
663+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
664+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
665+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
666+ pub struct AlterTypeRename {
667+ pub new_name : Ident ,
668+ }
669+
670+ /// See [AlterTypeOperation::AddValue]
671+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
672+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
673+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
674+ pub struct AlterTypeAddValue {
675+ pub if_not_exists : bool ,
676+ pub value : Ident ,
677+ pub position : Option < AlterTypeAddValuePosition > ,
678+ }
679+
680+ /// See [AlterTypeAddValue]
681+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
682+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
683+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
684+ pub enum AlterTypeAddValuePosition {
685+ Before ( Ident ) ,
686+ After ( Ident ) ,
687+ }
688+
689+ /// See [AlterTypeOperation::RenameValue]
690+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
691+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
692+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
693+ pub struct AlterTypeRenameValue {
694+ pub from : Ident ,
695+ pub to : Ident ,
696+ }
697+
698+ impl fmt:: Display for AlterTypeOperation {
699+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
700+ match self {
701+ Self :: Rename ( AlterTypeRename { new_name } ) => {
702+ write ! ( f, "RENAME TO {new_name}" )
703+ }
704+ Self :: AddValue ( AlterTypeAddValue {
705+ if_not_exists,
706+ value,
707+ position,
708+ } ) => {
709+ write ! ( f, "ADD VALUE" ) ?;
710+ if * if_not_exists {
711+ write ! ( f, " IF NOT EXISTS" ) ?;
712+ }
713+ write ! ( f, " {value}" ) ?;
714+ match position {
715+ Some ( AlterTypeAddValuePosition :: Before ( neighbor_value) ) => {
716+ write ! ( f, " BEFORE {neighbor_value}" ) ?;
717+ }
718+ Some ( AlterTypeAddValuePosition :: After ( neighbor_value) ) => {
719+ write ! ( f, " AFTER {neighbor_value}" ) ?;
720+ }
721+ None => { }
722+ } ;
723+ Ok ( ( ) )
724+ }
725+ Self :: RenameValue ( AlterTypeRenameValue { from, to } ) => {
726+ write ! ( f, "RENAME VALUE {from} TO {to}" )
727+ }
728+ }
729+ }
730+ }
731+
643732/// An `ALTER COLUMN` (`Statement::AlterTable`) operation
644733#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
645734#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
0 commit comments