Skip to content

Commit

Permalink
fix: fix sql parser on update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed May 13, 2024
1 parent f7d2ff9 commit 6c912c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion cmd/ormat/command/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"context"
"errors"
"fmt"
"log/slog"
"net/url"
"os"
Expand Down
7 changes: 7 additions & 0 deletions driver/mysql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,16 @@ func parseSqlColumnDefinition(col *sqlparser.ColumnDefinition) (*schema.Column,
if colType.Default != nil {
coldef.Default = &schema.Literal{V: string(colType.Default.Val)}
}
if colType.OnUpdate != nil {
coldef.AddAttrs(&mysql.OnUpdate{
Attr: nil,
A: string(colType.OnUpdate.Val),
})
}
if colType.Autoincrement {
coldef.AddAttrs(&mysql.AutoIncrement{})
}

if colType.Comment != nil {
coldef.AddAttrs(&schema.Comment{Text: string(colType.Comment.Val)})
}
Expand Down
5 changes: 5 additions & 0 deletions driver/mysql/sql_tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func parserCreateTableStmtColumn(col *ast.ColumnDef) (*schema.Column, error) {

case ast.ColumnOptionComment:
coldef.AddAttrs(&schema.Comment{Text: strings.Trim(formatExprNode(opt.Expr), `"`)})
case ast.ColumnOptionOnUpdate:
coldef.AddAttrs(&mysql.OnUpdate{
Attr: nil,
A: strings.Trim(formatExprNode(opt.Expr), `"`),
})
}
}

Expand Down

0 comments on commit 6c912c9

Please sign in to comment.