Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override identifier length for postgres #232

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type Config struct {
Conn gorm.ConnPool
}

var (
timeZoneMatcher = regexp.MustCompile("(time_zone|TimeZone)=(.*?)($|&| )")
defaultIdentifierLength = 63 //maximum identifier length for postgres
)

func Open(dsn string) gorm.Dialector {
return &Dialector{&Config{DSN: dsn}}
}
Expand All @@ -42,7 +47,20 @@ func (dialector Dialector) Name() string {
return "postgres"
}

var timeZoneMatcher = regexp.MustCompile("(time_zone|TimeZone)=(.*?)($|&| )")
func (dialector Dialector) Apply(config *gorm.Config) error {
var namingStartegy *schema.NamingStrategy
switch v := config.NamingStrategy.(type) {
case *schema.NamingStrategy:
namingStartegy = v
case schema.NamingStrategy:
namingStartegy = &v
case nil:
namingStartegy = &schema.NamingStrategy{}
}
namingStartegy.IdentifierMaxLength = defaultIdentifierLength
a631807682 marked this conversation as resolved.
Show resolved Hide resolved
config.NamingStrategy = namingStartegy
return nil
}

func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
callbackConfig := &callbacks.Config{
Expand Down
Loading