Skip to content

Commit 6358069

Browse files
committed
feat(go): use the same schema;
1 parent da51152 commit 6358069

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

db/postgres.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package db
22

33
import (
44
"fmt"
5+
"github.com/gravitl/netmaker/servercfg"
56
"os"
67
"strconv"
78

@@ -18,7 +19,7 @@ type postgresConnector struct{}
1819
// postgresConnector.connect connects and
1920
// initializes a connection to postgres.
2021
func (pg *postgresConnector) connect() (*gorm.DB, error) {
21-
pgConf := GetSQLConf()
22+
pgConf := servercfg.GetSQLConf()
2223
dsn := fmt.Sprintf(
2324
"host=%s port=%d user=%s password=%s dbname=%s sslmode=%s connect_timeout=5",
2425
pgConf.Host,
@@ -29,27 +30,11 @@ func (pg *postgresConnector) connect() (*gorm.DB, error) {
2930
pgConf.SSLMode,
3031
)
3132

32-
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
33+
return gorm.Open(postgres.Open(dsn), &gorm.Config{
3334
Logger: logger.Default.LogMode(logger.Silent),
3435
})
35-
if err != nil {
36-
return nil, err
37-
}
38-
39-
// ensure netmaker_v1 schema exists.
40-
err = db.Exec("CREATE SCHEMA IF NOT EXISTS netmaker_v1").Error
41-
if err != nil {
42-
return nil, err
43-
}
44-
45-
// set the netmaker_v1 schema as the default schema.
46-
err = db.Exec("SET search_path TO netmaker_v1").Error
47-
if err != nil {
48-
return nil, err
49-
}
50-
51-
return db, nil
5236
}
37+
5338
func GetSQLConf() config.SQLConfig {
5439
var cfg config.SQLConfig
5540
cfg.Host = GetSQLHost()

0 commit comments

Comments
 (0)