diff --git a/lib/db/schema/ddl/ddl.go b/lib/db/schema/ddl/ddl.go index 21dd584..3c52090 100644 --- a/lib/db/schema/ddl/ddl.go +++ b/lib/db/schema/ddl/ddl.go @@ -151,6 +151,7 @@ func FromStatement(stmt *gorm.Statement) Table { // fix gorm problem with primaryKey if (column.Type == "bigint(20)" || column.Type == "bigint" || column.Type == "int") && field.FieldType.Kind() == reflect.String { + fmt.Println("===>", column.Name, field.FieldType.Kind()) column.Type = "varchar" } if column.Type == "varchar" { @@ -203,7 +204,7 @@ func FromStatement(stmt *gorm.Statement) Table { } } - if column.Type == "TIMESTAMP" && column.Default == "" && !column.Nullable { + if (column.Type == "TIMESTAMP" || column.Type == "timestamp") && column.Default == "" && !column.Nullable { column.Default = "0000-00-00 00:00:00" } @@ -410,22 +411,22 @@ func (local Table) GetDiff(remote table.Table) []string { } if fieldType(strings.ToLower(field.Type)) != fieldType(strings.ToLower(r.ColumnType)) { - queries = append(queries, fmt.Sprintf("-- type does not match. new:%s old:%s", fieldType(field.Type), strings.ToLower(r.ColumnType))) + queries = append(queries, fmt.Sprintf("-- column %s type does not match. new:%s old:%s", field.Name, fieldType(field.Type), strings.ToLower(r.ColumnType))) diff = true } if len(field.Collate) > 0 && strings.ToLower(field.Collate) != strings.ToLower(r.Collation) { - queries = append(queries, fmt.Sprintf("-- collation does not match. new:%s old:%s", field.Collate, r.Collation)) + queries = append(queries, fmt.Sprintf("-- column %s collation does not match. new:%s old:%s", field.Name, field.Collate, r.Collation)) diff = true } if len(field.Charset) > 0 && strings.ToLower(field.Charset) != strings.ToLower(r.CharacterSet) { - queries = append(queries, fmt.Sprintf("-- charset does not match. new:%s old:%s", field.Charset, r.CharacterSet)) + queries = append(queries, fmt.Sprintf("-- column %s charset does not match. new:%s old:%s", field.Name, field.Charset, r.CharacterSet)) diff = true } if field.Comment != r.Comment { - queries = append(queries, fmt.Sprintf("-- comment does not match. new:%s old:%s", field.Comment, r.Comment)) + queries = append(queries, fmt.Sprintf("-- column %s comment does not match. new:%s old:%s", field.Name, field.Comment, r.Comment)) diff = true } - if field.Default != fieldType(getString(r.ColumnDefault)) { + if field.Default != getString(r.ColumnDefault) { var skip = false for _, row := range InternalFunctions { if slices.Contains(row, field.Default) && slices.Contains(row, getString(r.ColumnDefault)) { @@ -437,17 +438,17 @@ func (local Table) GetDiff(remote table.Table) []string { } if !skip && !(field.Default == "NULL" && r.ColumnDefault == nil) { - queries = append(queries, fmt.Sprintf("-- default value does not match. new:%s old:%s", field.Default, getString(r.ColumnDefault))) + queries = append(queries, fmt.Sprintf("-- field %s default value does not match. new:%s old:%s", field.Name, field.Default, getString(r.ColumnDefault))) diff = true } } if field.Nullable != (r.Nullable == "YES") { - queries = append(queries, fmt.Sprintf("-- nullable does not match. new:%t old:%t", field.Nullable, r.Nullable == "YES")) + queries = append(queries, fmt.Sprintf("-- column %s nullable does not match. new:%t old:%t", field.Name, field.Nullable, r.Nullable == "YES")) diff = true } var needPK = false if field.AutoIncrement && strings.ToLower(r.Extra) != "auto_increment" { - afterPK = append(afterPK, fmt.Sprintf("-- auto_increment does not match. new:%t old:%t", field.AutoIncrement, !field.AutoIncrement)) + afterPK = append(afterPK, fmt.Sprintf("-- field %s auto_increment does not match. new:%t old:%t", field.Name, field.AutoIncrement, !field.AutoIncrement)) diff = true needPK = true } diff --git a/lib/log/log.go b/lib/log/log.go index 9a9ed82..41187d7 100644 --- a/lib/log/log.go +++ b/lib/log/log.go @@ -113,10 +113,11 @@ func msg(message any, level Level, params ...any) { return } _, file, line, _ := runtime.Caller(2 + stackTraceLevel) + entry := Entry{ Level: levels[level], Date: time.Now(), - File: file[len(wd)+1:], + File: file, Line: line, Message: fmt.Sprintf(fmt.Sprint(message), params...), } diff --git a/lib/ptr/ptr.go b/lib/ptr/ptr.go new file mode 100644 index 0000000..f34b182 --- /dev/null +++ b/lib/ptr/ptr.go @@ -0,0 +1,83 @@ +package ptr + +import "time" + +// Int returns a pointer to the given int value. +func Int(v int) *int { + return &v +} + +// Int8 returns a pointer to the given int8 value. +func Int8(v int8) *int8 { + return &v +} + +// Int16 returns a pointer to the given int16 value. +func Int16(v int16) *int16 { + return &v +} + +// Int32 returns a pointer to the given int32 value. +func Int32(v int32) *int32 { + return &v +} + +// Int64 returns a pointer to the given int64 value. +func Int64(v int64) *int64 { + return &v +} + +// Uint returns a pointer to the given uint value. +func Uint(v uint) *uint { + return &v +} + +// Uint8 returns a pointer to the given uint8 value. +func Uint8(v uint8) *uint8 { + return &v +} + +// Uint16 returns a pointer to the given uint16 value. +func Uint16(v uint16) *uint16 { + return &v +} + +// Uint32 returns a pointer to the given uint32 value. +func Uint32(v uint32) *uint32 { + return &v +} + +// Uint64 returns a pointer to the given uint64 value. +func Uint64(v uint64) *uint64 { + return &v +} + +// Float32 returns a pointer to the given float32 value. +func Float32(v float32) *float32 { + return &v +} + +// Float64 returns a pointer to the given float64 value. +func Float64(v float64) *float64 { + return &v +} + +// String returns a pointer to the given string value. +func String(v string) *string { + return &v +} + +// Bool returns a pointer to the given bool value. +func Bool(v bool) *bool { + return &v +} + +// Time returns a pointer to the given time.Time value. +func Time(v time.Time) *time.Time { + return &v +} + +// Interface returns a pointer to the given interface{} value. +func Interface(v interface{}) *interface{} { + return &v +}