Skip to content

Add support for CHANGE COLUMN in MySQL #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* name: Placeholder :exec */
SELECT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE foo (bar text);
ALTER TABLE foo CHANGE COLUMN bar baz text;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
24 changes: 23 additions & 1 deletion internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,29 @@ func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
})

case pcast.AlterTableChangeColumn:
// spew.Dump("change column", spec)
oldName := spec.OldColumnName.String()
alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{
Name: &oldName,
Subtype: ast.AT_DropColumn,
})

for _, def := range spec.NewColumns {
name := def.Name.String()
columnDef := ast.ColumnDef{
Colname: def.Name.String(),
TypeName: &ast.TypeName{Name: types.TypeStr(def.Tp.Tp)},
IsNotNull: isNotNull(def),
}
if def.Tp.Flen >= 0 {
length := def.Tp.Flen
columnDef.Length = &length
}
alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{
Name: &name,
Subtype: ast.AT_AddColumn,
Def: &columnDef,
})
}

case pcast.AlterTableModifyColumn:
for _, def := range spec.NewColumns {
Expand Down