fix migration

This commit is contained in:
Fran Jurmanović
2023-04-13 14:35:36 +02:00
parent e1f9de58cd
commit 062bb74221
21 changed files with 80 additions and 87 deletions

View File

@@ -2,7 +2,6 @@ package db
import (
"context"
"fmt"
"log"
"os"
"wallet-api/pkg/utl/common"
@@ -34,14 +33,18 @@ func (e *LoggerHook) AfterQuery(ctx context.Context, qe *pg.QueryEvent) error {
func CreateConnection(ctx context.Context, dbUrl string) *pg.DB {
opt, err := pg.ParseURL(dbUrl)
common.CheckError(err)
file, err := os.OpenFile("querys.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
file, err := os.OpenFile("querys.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
common.CheckError(err)
QueryLogger := log.New(file, "Query: ", log.Ldate|log.Ltime|log.Lshortfile)
conn := pg.Connect(opt)
err = conn.Ping(ctx)
if err != nil {
log.Fatalln(err)
}
loggerHook := LoggerHook{QueryLogger}
conn.AddQueryHook(&loggerHook)
db := conn.WithContext(ctx)
fmt.Println("Successfully connected!")
log.Printf("Successfully connected to %s!", dbUrl)
return db
}