Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 6c912c9

Browse files
committed
fix: fix sql parser on update bug
1 parent f7d2ff9 commit 6c912c9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

cmd/ormat/command/helper.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package command
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"log/slog"
87
"net/url"
98
"os"

driver/mysql/sql.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,16 @@ func parseSqlColumnDefinition(col *sqlparser.ColumnDefinition) (*schema.Column,
102102
if colType.Default != nil {
103103
coldef.Default = &schema.Literal{V: string(colType.Default.Val)}
104104
}
105+
if colType.OnUpdate != nil {
106+
coldef.AddAttrs(&mysql.OnUpdate{
107+
Attr: nil,
108+
A: string(colType.OnUpdate.Val),
109+
})
110+
}
105111
if colType.Autoincrement {
106112
coldef.AddAttrs(&mysql.AutoIncrement{})
107113
}
114+
108115
if colType.Comment != nil {
109116
coldef.AddAttrs(&schema.Comment{Text: string(colType.Comment.Val)})
110117
}

driver/mysql/sql_tidb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func parserCreateTableStmtColumn(col *ast.ColumnDef) (*schema.Column, error) {
108108

109109
case ast.ColumnOptionComment:
110110
coldef.AddAttrs(&schema.Comment{Text: strings.Trim(formatExprNode(opt.Expr), `"`)})
111+
case ast.ColumnOptionOnUpdate:
112+
coldef.AddAttrs(&mysql.OnUpdate{
113+
Attr: nil,
114+
A: strings.Trim(formatExprNode(opt.Expr), `"`),
115+
})
111116
}
112117
}
113118

0 commit comments

Comments
 (0)