@@ -35,14 +35,19 @@ func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
3535 case pcast .AlterTableAddColumns :
3636 for _ , def := range spec .NewColumns {
3737 name := def .Name .String ()
38+ columnDef := ast.ColumnDef {
39+ Colname : def .Name .String (),
40+ TypeName : & ast.TypeName {Name : types .TypeStr (def .Tp .Tp )},
41+ IsNotNull : isNotNull (def ),
42+ }
43+ if def .Tp .Flen >= 0 {
44+ length := def .Tp .Flen
45+ columnDef .Length = & length
46+ }
3847 alt .Cmds .Items = append (alt .Cmds .Items , & ast.AlterTableCmd {
3948 Name : & name ,
4049 Subtype : ast .AT_AddColumn ,
41- Def : & ast.ColumnDef {
42- Colname : def .Name .String (),
43- TypeName : & ast.TypeName {Name : types .TypeStr (def .Tp .Tp )},
44- IsNotNull : isNotNull (def ),
45- },
50+ Def : & columnDef ,
4651 })
4752 }
4853
@@ -60,18 +65,23 @@ func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
6065 case pcast .AlterTableModifyColumn :
6166 for _ , def := range spec .NewColumns {
6267 name := def .Name .String ()
68+ columnDef := ast.ColumnDef {
69+ Colname : def .Name .String (),
70+ TypeName : & ast.TypeName {Name : types .TypeStr (def .Tp .Tp )},
71+ IsNotNull : isNotNull (def ),
72+ }
73+ if def .Tp .Flen >= 0 {
74+ length := def .Tp .Flen
75+ columnDef .Length = & length
76+ }
6377 alt .Cmds .Items = append (alt .Cmds .Items , & ast.AlterTableCmd {
6478 Name : & name ,
6579 Subtype : ast .AT_DropColumn ,
6680 })
6781 alt .Cmds .Items = append (alt .Cmds .Items , & ast.AlterTableCmd {
6882 Name : & name ,
6983 Subtype : ast .AT_AddColumn ,
70- Def : & ast.ColumnDef {
71- Colname : def .Name .String (),
72- TypeName : & ast.TypeName {Name : types .TypeStr (def .Tp .Tp )},
73- IsNotNull : isNotNull (def ),
74- },
84+ Def : & columnDef ,
7585 })
7686 }
7787
@@ -224,13 +234,18 @@ func (c *cc) convertCreateTableStmt(n *pcast.CreateTableStmt) ast.Node {
224234 }
225235 }
226236 }
227- create . Cols = append ( create . Cols , & ast.ColumnDef {
237+ columnDef := ast.ColumnDef {
228238 Colname : def .Name .String (),
229239 TypeName : & ast.TypeName {Name : types .TypeStr (def .Tp .Tp )},
230240 IsNotNull : isNotNull (def ),
231241 Comment : comment ,
232242 Vals : vals ,
233- })
243+ }
244+ if def .Tp .Flen >= 0 {
245+ length := def .Tp .Flen
246+ columnDef .Length = & length
247+ }
248+ create .Cols = append (create .Cols , & columnDef )
234249 }
235250 for _ , opt := range n .Options {
236251 switch opt .Tp {
0 commit comments