Skip to content

Commit 61c661c

Browse files
authored
Support ALTER INDEX {INDEX_NAME} RENAME TO {NEW_INDEX_NAME} (#767)
* test: add a case `rename_index` * feat: add AlterIndex match arm * fix: remove todo with self.expected * chore: add comment to unreachable
1 parent f0870fd commit 61c661c

File tree

4 files changed

+224
-159
lines changed

4 files changed

+224
-159
lines changed

src/ast/ddl.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ pub enum AlterTableOperation {
9494
},
9595
}
9696

97+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
98+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
99+
pub enum AlterIndexOperation {
100+
RenameIndex { index_name: ObjectName },
101+
}
102+
97103
impl fmt::Display for AlterTableOperation {
98104
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
99105
match self {
@@ -200,6 +206,16 @@ impl fmt::Display for AlterTableOperation {
200206
}
201207
}
202208

209+
impl fmt::Display for AlterIndexOperation {
210+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
211+
match self {
212+
AlterIndexOperation::RenameIndex { index_name } => {
213+
write!(f, "RENAME TO {}", index_name)
214+
}
215+
}
216+
}
217+
}
218+
203219
/// An `ALTER COLUMN` (`Statement::AlterTable`) operation
204220
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
205221
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

src/ast/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub use self::data_type::{
2626
CharLengthUnits, CharacterLength, DataType, ExactNumberInfo, TimezoneInfo,
2727
};
2828
pub use self::ddl::{
29-
AlterColumnOperation, AlterTableOperation, ColumnDef, ColumnOption, ColumnOptionDef, IndexType,
30-
KeyOrIndexDisplay, ReferentialAction, TableConstraint,
29+
AlterColumnOperation, AlterIndexOperation, AlterTableOperation, ColumnDef, ColumnOption,
30+
ColumnOptionDef, IndexType, KeyOrIndexDisplay, ReferentialAction, TableConstraint,
3131
};
3232
pub use self::operator::{BinaryOperator, UnaryOperator};
3333
pub use self::query::{
@@ -1250,6 +1250,10 @@ pub enum Statement {
12501250
name: ObjectName,
12511251
operation: AlterTableOperation,
12521252
},
1253+
AlterIndex {
1254+
name: ObjectName,
1255+
operation: AlterIndexOperation,
1256+
},
12531257
/// DROP
12541258
Drop {
12551259
/// The type of the object to drop: TABLE, VIEW, etc.
@@ -2275,6 +2279,9 @@ impl fmt::Display for Statement {
22752279
Statement::AlterTable { name, operation } => {
22762280
write!(f, "ALTER TABLE {} {}", name, operation)
22772281
}
2282+
Statement::AlterIndex { name, operation } => {
2283+
write!(f, "ALTER INDEX {} {}", name, operation)
2284+
}
22782285
Statement::Drop {
22792286
object_type,
22802287
if_exists,

0 commit comments

Comments
 (0)