Skip to content

Commit

Permalink
add support for ALTER TABLE ... RENAME COLUMN syntax (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangwz authored and leoppro committed Aug 21, 2019
1 parent 96e1f76 commit dd016b8
Show file tree
Hide file tree
Showing 4 changed files with 3,976 additions and 3,939 deletions.
11 changes: 11 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,7 @@ const (
AlterTableDropForeignKey
AlterTableModifyColumn
AlterTableChangeColumn
AlterTableRenameColumn
AlterTableRenameTable
AlterTableAlterColumn
AlterTableLock
Expand Down Expand Up @@ -1945,6 +1946,7 @@ type AlterTableSpec struct {
NewTable *TableName
NewColumns []*ColumnDef
OldColumnName *ColumnName
NewColumnName *ColumnName
Position *ColumnPosition
LockType LockType
Algorithm AlgorithmType
Expand Down Expand Up @@ -2067,6 +2069,15 @@ func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
if err := n.Position.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableSpec.Position")
}
case AlterTableRenameColumn:
ctx.WriteKeyWord("RENAME COLUMN ")
if err := n.OldColumnName.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableSpec.OldColumnName")
}
ctx.WriteKeyWord(" TO ")
if err := n.NewColumnName.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AlterTableSpec.NewColumnName")
}
case AlterTableRenameTable:
ctx.WriteKeyWord("RENAME AS ")
if err := n.NewTable.Restore(ctx); err != nil {
Expand Down
Loading

0 comments on commit dd016b8

Please sign in to comment.