Skip to content

Commit 3692119

Browse files
authored
fix: namer identifier max length (#258)
1 parent 2f9abde commit 3692119

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

postgres.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,25 @@ func (dialector Dialector) Name() string {
4848
}
4949

5050
func (dialector Dialector) Apply(config *gorm.Config) error {
51-
var namingStartegy *schema.NamingStrategy
51+
if config.NamingStrategy == nil {
52+
config.NamingStrategy = schema.NamingStrategy{
53+
IdentifierMaxLength: defaultIdentifierLength,
54+
}
55+
return nil
56+
}
57+
5258
switch v := config.NamingStrategy.(type) {
5359
case *schema.NamingStrategy:
54-
namingStartegy = v
60+
if v.IdentifierMaxLength <= 0 {
61+
v.IdentifierMaxLength = defaultIdentifierLength
62+
}
5563
case schema.NamingStrategy:
56-
namingStartegy = &v
57-
case nil:
58-
namingStartegy = &schema.NamingStrategy{}
59-
}
60-
if namingStartegy.IdentifierMaxLength <= 0 {
61-
namingStartegy.IdentifierMaxLength = defaultIdentifierLength
64+
if v.IdentifierMaxLength <= 0 {
65+
v.IdentifierMaxLength = defaultIdentifierLength
66+
config.NamingStrategy = v
67+
}
6268
}
63-
config.NamingStrategy = namingStartegy
69+
6470
return nil
6571
}
6672

0 commit comments

Comments
 (0)