Skip to content

Commit

Permalink
only set the table prefix if a db schema is set
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscannon committed Jan 3, 2024
1 parent 9d90c6c commit 5f0c214
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ func main() {
var err error

dbURI := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s sslrootcert=%s", serverConfig.DB_HOST, serverConfig.DB_USER, serverConfig.DB_PASSWORD, serverConfig.DB_NAME, serverConfig.DB_PORT, serverConfig.DB_SSLMODE, serverConfig.DB_SSLROOTCERT)
gormConfig := &gorm.Config{NamingStrategy: schema.NamingStrategy{
TablePrefix: serverConfig.DB_SCHEMA,
}}

gormConfig := &gorm.Config{}
if serverConfig.DB_SCHEMA != "" {
gormConfig.NamingStrategy = schema.NamingStrategy{TablePrefix: serverConfig.DB_SCHEMA}
}

if log.Level() != zap.DebugLevel {
gormConfig.Logger = gormlogger.Default.LogMode(gormlogger.Silent)
}
Expand Down

0 comments on commit 5f0c214

Please sign in to comment.