diff --git a/schema/naming.go b/schema/naming.go index 1962c3c6..d53942e4 100644 --- a/schema/naming.go +++ b/schema/naming.go @@ -2,6 +2,7 @@ package schema import ( "crypto/sha1" + "encoding/hex" "fmt" "strings" "unicode/utf8" @@ -80,7 +81,7 @@ func (ns NamingStrategy) formatName(prefix, table, name string) string { h.Write([]byte(formattedName)) bs := h.Sum(nil) - formattedName = fmt.Sprintf("%v%v%v", prefix, table, name)[0:56] + string(bs)[:8] + formattedName = fmt.Sprintf("%v%v%v", prefix, table, name)[0:56] + hex.EncodeToString(bs)[:8] } return formattedName } diff --git a/schema/naming_test.go b/schema/naming_test.go index 08f8d498..face9364 100644 --- a/schema/naming_test.go +++ b/schema/naming_test.go @@ -168,3 +168,12 @@ func TestCustomReplacerWithNoLowerCase(t *testing.T) { t.Errorf("invalid column name generated, got %v", columdName) } } + +func TestFormatNameWithStringLongerThan64Characters(t *testing.T) { + var ns = NamingStrategy{} + + formattedName := ns.formatName("prefix", "table", "thisIsAVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString") + if formattedName != "prefixtablethisIsAVeryVeryVeryVeryVeryVeryVeryVeryVeryLo180f2c67" { + t.Errorf("invalid formatted name generated, got %v", formattedName) + } +}