rename one of the packages - db -> postgres

This commit is contained in:
Dawid Wysokiński 2021-05-03 16:35:24 +02:00
parent cb56b313ee
commit 34b0ef9949
4 changed files with 9 additions and 9 deletions

View File

@ -12,7 +12,7 @@ import (
"net/http"
"github.com/tribalwarshelp/cron/internal/cron/queue"
"github.com/tribalwarshelp/cron/internal/db"
"github.com/tribalwarshelp/cron/internal/postgres"
)
const (
@ -48,7 +48,7 @@ func (t *taskLoadServersAndUpdateData) execute(version *twmodel.Version) error {
VersionCode: version.Code,
Version: version,
}
if err := db.CreateSchema(t.db, server); err != nil {
if err := postgres.CreateSchema(t.db, server); err != nil {
logrus.Warn(errors.Wrapf(err, "taskLoadServersAndUpdateData.execute: %s: couldn't create the schema", server.Key))
continue
}

View File

@ -1,4 +1,4 @@
package db
package postgres
import (
"fmt"
@ -11,13 +11,13 @@ import (
"github.com/tribalwarshelp/shared/tw/twmodel"
)
var log = logrus.WithField("package", "db")
var log = logrus.WithField("package", "postgres")
type Config struct {
LogQueries bool
}
func New(cfg *Config) (*pg.DB, error) {
func Connect(cfg *Config) (*pg.DB, error) {
db := pg.Connect(prepareOptions())
if cfg != nil && cfg.LogQueries {
@ -28,7 +28,7 @@ func New(cfg *Config) (*pg.DB, error) {
}
if err := prepareDB(db); err != nil {
return nil, errors.Wrap(err, "New")
return nil, errors.Wrap(err, "Connect")
}
return db, nil

View File

@ -1,4 +1,4 @@
package db
package postgres
const (
allSpecialServersPGInsertStatements = `

View File

@ -14,7 +14,7 @@ import (
"github.com/sirupsen/logrus"
twhelpcron "github.com/tribalwarshelp/cron/internal/cron"
"github.com/tribalwarshelp/cron/internal/db"
"github.com/tribalwarshelp/cron/internal/postgres"
"github.com/joho/godotenv"
"github.com/robfig/cron/v3"
@ -38,7 +38,7 @@ func main() {
}
}()
dbConn, err := db.New(&db.Config{LogQueries: envutil.GetenvBool("LOG_DB_QUERIES")})
dbConn, err := postgres.Connect(&postgres.Config{LogQueries: envutil.GetenvBool("LOG_DB_QUERIES")})
if err != nil {
logrus.Fatal(errors.Wrap(err, "Couldn't connect to the db"))
}