Skip to content

Commit dafcead

Browse files
committed
Move namespace configuration into connection creator
This allows testing db namespaces in tests
1 parent 6226df2 commit dafcead

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

cmd/multi_cmd.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ func multi(cmd *cobra.Command, args []string) {
2525
if globalConfig.OperatorToken == "" {
2626
logrus.Fatal("Operator token secret is required")
2727
}
28-
if globalConfig.DB.Namespace != "" {
29-
models.Namespace = globalConfig.DB.Namespace
30-
}
3128

3229
db, err := models.Connect(globalConfig)
3330
if err != nil {

cmd/root_cmd.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/spf13/cobra"
66

77
"github.com/netlify/gocommerce/conf"
8-
"github.com/netlify/gocommerce/models"
98
)
109

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

39-
if globalConfig.DB.Namespace != "" {
40-
models.Namespace = globalConfig.DB.Namespace
41-
}
4238
fn(globalConfig, config)
4339
}

models/connection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ var Namespace string
2222

2323
// Connect will connect to that storage engine
2424
func Connect(config *conf.GlobalConfiguration) (*gorm.DB, error) {
25+
if config.DB.Namespace != "" {
26+
Namespace = config.DB.Namespace
27+
}
28+
2529
if config.DB.Dialect == "" {
2630
config.DB.Dialect = config.DB.Driver
2731
}

0 commit comments

Comments
 (0)