Fix issue with failing db cmds
This commit is contained in:
parent
1370d24985
commit
75ff5510d4
|
@ -55,7 +55,7 @@ func cmdDBReset(cmd *cobra.Command, args []string) {
|
||||||
func cmdDBCreate(cmd *cobra.Command, args []string) {
|
func cmdDBCreate(cmd *cobra.Command, args []string) {
|
||||||
initConfOnce()
|
initConfOnce()
|
||||||
|
|
||||||
db, err := initDB(conf)
|
db, err := initDB(conf, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ERR failed to connect to database: %s", err)
|
log.Fatalf("ERR failed to connect to database: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func cmdDBCreate(cmd *cobra.Command, args []string) {
|
||||||
func cmdDBDrop(cmd *cobra.Command, args []string) {
|
func cmdDBDrop(cmd *cobra.Command, args []string) {
|
||||||
initConfOnce()
|
initConfOnce()
|
||||||
|
|
||||||
db, err := initDB(conf)
|
db, err := initDB(conf, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ERR failed to connect to database: %s", err)
|
log.Fatalf("ERR failed to connect to database: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ func cmdDBMigrate(cmd *cobra.Command, args []string) {
|
||||||
initConfOnce()
|
initConfOnce()
|
||||||
dest := args[0]
|
dest := args[0]
|
||||||
|
|
||||||
conn, err := initDB(conf)
|
conn, err := initDB(conf, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ERR failed to connect to database: %s", err)
|
log.Fatalf("ERR failed to connect to database: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ func cmdDBMigrate(cmd *cobra.Command, args []string) {
|
||||||
func cmdDBStatus(cmd *cobra.Command, args []string) {
|
func cmdDBStatus(cmd *cobra.Command, args []string) {
|
||||||
initConfOnce()
|
initConfOnce()
|
||||||
|
|
||||||
db, err := initDB(conf)
|
db, err := initDB(conf, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ERR failed to connect to database: %s", err)
|
log.Fatalf("ERR failed to connect to database: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func cmdDBSeed(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
conf.Production = false
|
conf.Production = false
|
||||||
|
|
||||||
db, err = initDB(conf)
|
db, err = initDB(conf, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ERR failed to connect to database: %s", err)
|
log.Fatalf("ERR failed to connect to database: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func cmdServ(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
initWatcher()
|
initWatcher()
|
||||||
|
|
||||||
db, err = initDB(conf)
|
db, err = initDB(conf, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalInProd(err, "failed to connect to database")
|
fatalInProd(err, "failed to connect to database")
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func initConf() (*Config, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDB(c *Config) (*sql.DB, error) {
|
func initDB(c *Config, useDB bool) (*sql.DB, error) {
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -107,7 +107,6 @@ func initDB(c *Config) (*sql.DB, error) {
|
||||||
config, _ := pgx.ParseConfig("")
|
config, _ := pgx.ParseConfig("")
|
||||||
config.Host = c.DB.Host
|
config.Host = c.DB.Host
|
||||||
config.Port = c.DB.Port
|
config.Port = c.DB.Port
|
||||||
config.Database = c.DB.DBName
|
|
||||||
config.User = c.DB.User
|
config.User = c.DB.User
|
||||||
config.Password = c.DB.Password
|
config.Password = c.DB.Password
|
||||||
config.RuntimeParams = map[string]string{
|
config.RuntimeParams = map[string]string{
|
||||||
|
@ -115,6 +114,10 @@ func initDB(c *Config) (*sql.DB, error) {
|
||||||
"search_path": c.DB.Schema,
|
"search_path": c.DB.Schema,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if useDB {
|
||||||
|
config.Database = c.DB.DBName
|
||||||
|
}
|
||||||
|
|
||||||
// switch c.LogLevel {
|
// switch c.LogLevel {
|
||||||
// case "debug":
|
// case "debug":
|
||||||
// config.LogLevel = pgx.LogLevelDebug
|
// config.LogLevel = pgx.LogLevelDebug
|
||||||
|
|
Loading…
Reference in New Issue