@@ -151,6 +151,7 @@ func FromStatement(stmt *gorm.Statement) Table {
151151
152152 // fix gorm problem with primaryKey
153153 if (column .Type == "bigint(20)" || column .Type == "bigint" || column .Type == "int" ) && field .FieldType .Kind () == reflect .String {
154+ fmt .Println ("===>" , column .Name , field .FieldType .Kind ())
154155 column .Type = "varchar"
155156 }
156157 if column .Type == "varchar" {
@@ -203,7 +204,7 @@ func FromStatement(stmt *gorm.Statement) Table {
203204 }
204205 }
205206
206- if column .Type == "TIMESTAMP" && column .Default == "" && ! column .Nullable {
207+ if ( column .Type == "TIMESTAMP" || column . Type == "timestamp" ) && column .Default == "" && ! column .Nullable {
207208 column .Default = "0000-00-00 00:00:00"
208209 }
209210
@@ -410,22 +411,22 @@ func (local Table) GetDiff(remote table.Table) []string {
410411 }
411412
412413 if fieldType (strings .ToLower (field .Type )) != fieldType (strings .ToLower (r .ColumnType )) {
413- queries = append (queries , fmt .Sprintf ("-- type does not match. new:%s old:%s" , fieldType (field .Type ), strings .ToLower (r .ColumnType )))
414+ queries = append (queries , fmt .Sprintf ("-- column %s type does not match. new:%s old:%s" , field . Name , fieldType (field .Type ), strings .ToLower (r .ColumnType )))
414415 diff = true
415416 }
416417 if len (field .Collate ) > 0 && strings .ToLower (field .Collate ) != strings .ToLower (r .Collation ) {
417- queries = append (queries , fmt .Sprintf ("-- collation does not match. new:%s old:%s" , field .Collate , r .Collation ))
418+ queries = append (queries , fmt .Sprintf ("-- column %s collation does not match. new:%s old:%s" , field . Name , field .Collate , r .Collation ))
418419 diff = true
419420 }
420421 if len (field .Charset ) > 0 && strings .ToLower (field .Charset ) != strings .ToLower (r .CharacterSet ) {
421- queries = append (queries , fmt .Sprintf ("-- charset does not match. new:%s old:%s" , field .Charset , r .CharacterSet ))
422+ queries = append (queries , fmt .Sprintf ("-- column %s charset does not match. new:%s old:%s" , field . Name , field .Charset , r .CharacterSet ))
422423 diff = true
423424 }
424425 if field .Comment != r .Comment {
425- queries = append (queries , fmt .Sprintf ("-- comment does not match. new:%s old:%s" , field .Comment , r .Comment ))
426+ queries = append (queries , fmt .Sprintf ("-- column %s comment does not match. new:%s old:%s" , field . Name , field .Comment , r .Comment ))
426427 diff = true
427428 }
428- if field .Default != fieldType ( getString (r .ColumnDefault ) ) {
429+ if field .Default != getString (r .ColumnDefault ) {
429430 var skip = false
430431 for _ , row := range InternalFunctions {
431432 if slices .Contains (row , field .Default ) && slices .Contains (row , getString (r .ColumnDefault )) {
@@ -437,17 +438,17 @@ func (local Table) GetDiff(remote table.Table) []string {
437438 }
438439
439440 if ! skip && ! (field .Default == "NULL" && r .ColumnDefault == nil ) {
440- queries = append (queries , fmt .Sprintf ("-- default value does not match. new:%s old:%s" , field .Default , getString (r .ColumnDefault )))
441+ queries = append (queries , fmt .Sprintf ("-- field %s default value does not match. new:%s old:%s" , field . Name , field .Default , getString (r .ColumnDefault )))
441442 diff = true
442443 }
443444 }
444445 if field .Nullable != (r .Nullable == "YES" ) {
445- queries = append (queries , fmt .Sprintf ("-- nullable does not match. new:%t old:%t" , field .Nullable , r .Nullable == "YES" ))
446+ queries = append (queries , fmt .Sprintf ("-- column %s nullable does not match. new:%t old:%t" , field . Name , field .Nullable , r .Nullable == "YES" ))
446447 diff = true
447448 }
448449 var needPK = false
449450 if field .AutoIncrement && strings .ToLower (r .Extra ) != "auto_increment" {
450- afterPK = append (afterPK , fmt .Sprintf ("-- auto_increment does not match. new:%t old:%t" , field .AutoIncrement , ! field .AutoIncrement ))
451+ afterPK = append (afterPK , fmt .Sprintf ("-- field %s auto_increment does not match. new:%t old:%t" , field . Name , field .AutoIncrement , ! field .AutoIncrement ))
451452 diff = true
452453 needPK = true
453454 }
0 commit comments