Permalink
Browse files

Move namespace configuration into connection creator

This allows testing db namespaces in tests
  • Loading branch information...
mraerino committed Jan 25, 2019
1 parent 6226df2 commit dafcead48615c4efe7548086b2d983726aeef56f
Showing with 4 additions and 7 deletions.
  1. +0 −3 cmd/multi_cmd.go
  2. +0 −4 cmd/root_cmd.go
  3. +4 −0 models/connection.go
@@ -25,9 +25,6 @@ func multi(cmd *cobra.Command, args []string) {
if globalConfig.OperatorToken == "" {
logrus.Fatal("Operator token secret is required")
}
if globalConfig.DB.Namespace != "" {
models.Namespace = globalConfig.DB.Namespace
}

db, err := models.Connect(globalConfig)
if err != nil {
@@ -5,7 +5,6 @@ import (
"github.com/spf13/cobra"

"github.com/netlify/gocommerce/conf"
"github.com/netlify/gocommerce/models"
)

var configFile = ""
@@ -36,8 +35,5 @@ func execWithConfig(cmd *cobra.Command, fn func(globalConfig *conf.GlobalConfigu
logrus.Fatalf("Failed to load configuration: %+v", err)
}

if globalConfig.DB.Namespace != "" {
models.Namespace = globalConfig.DB.Namespace
}
fn(globalConfig, config)
}
@@ -22,6 +22,10 @@ var Namespace string

// Connect will connect to that storage engine
func Connect(config *conf.GlobalConfiguration) (*gorm.DB, error) {
if config.DB.Namespace != "" {
Namespace = config.DB.Namespace
}

if config.DB.Dialect == "" {
config.DB.Dialect = config.DB.Driver
}

0 comments on commit dafcead

Please sign in to comment.