Skip to content

Commit

Permalink
fix: namer identifier max length
Browse files Browse the repository at this point in the history
  • Loading branch information
a631807682 committed Mar 6, 2024
1 parent 2f9abde commit 680a517
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,25 @@ func (dialector Dialector) Name() string {
}

func (dialector Dialector) Apply(config *gorm.Config) error {
var namingStartegy *schema.NamingStrategy
if config.NamingStrategy == nil {
config.NamingStrategy = schema.NamingStrategy{
IdentifierMaxLength: defaultIdentifierLength,
}
return nil
}

switch v := config.NamingStrategy.(type) {
case *schema.NamingStrategy:
namingStartegy = v
if v.IdentifierMaxLength <= 0 {
v.IdentifierMaxLength = defaultIdentifierLength
}
case schema.NamingStrategy:
namingStartegy = &v
case nil:
namingStartegy = &schema.NamingStrategy{}
}
if namingStartegy.IdentifierMaxLength <= 0 {
namingStartegy.IdentifierMaxLength = defaultIdentifierLength
if v.IdentifierMaxLength <= 0 {
v.IdentifierMaxLength = defaultIdentifierLength
config.NamingStrategy = v
}
}
config.NamingStrategy = namingStartegy

return nil
}

Expand Down

0 comments on commit 680a517

Please sign in to comment.