Skip to content

Commit

Permalink
PR feedback and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst committed Dec 6, 2023
1 parent f8280f7 commit 6ab2cdc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
24 changes: 10 additions & 14 deletions storage/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
url2 "net/url"
"net/url"
"path"
"strings"
"sync"
"time"

"github.com/amacneil/dbmate/v2/pkg/dbmate"
_ "github.com/amacneil/dbmate/v2/pkg/driver/mysql"
_ "github.com/amacneil/dbmate/v2/pkg/driver/postgres"
_ "github.com/amacneil/dbmate/v2/pkg/driver/sqlite"
"github.com/nuts-foundation/go-stoabs"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/storage/log"
"github.com/redis/go-redis/v9"
"github.com/sirupsen/logrus"

_ "github.com/amacneil/dbmate/v2/pkg/driver/mysql"
_ "github.com/amacneil/dbmate/v2/pkg/driver/postgres"
_ "github.com/amacneil/dbmate/v2/pkg/driver/sqlite"
)

const storeShutdownTimeout = 5 * time.Second
Expand Down Expand Up @@ -176,11 +174,12 @@ func (e *engine) initSQLDatabase() error {
}
log.Logger().Debug("Running database migrations...")

url, _ := url2.Parse(fmt.Sprintf("sqlite:%s", connectionString))
db := dbmate.New(url)
dbURL, _ := url.Parse(fmt.Sprintf("sqlite:%s", connectionString))
db := dbmate.New(dbURL)
db.FS = sqlMigrationsFS
db.MigrationsDir = []string{"sql_migrations"}
db.AutoDumpSchema = false
db.Log = sqlMigrationLogger{}

return db.CreateAndMigrate()
}
Expand Down Expand Up @@ -247,10 +246,7 @@ func (p *provider) getStore(moduleName string, name string, adapter database) (s
type sqlMigrationLogger struct {
}

func (m sqlMigrationLogger) Printf(format string, v ...interface{}) {
log.Logger().Infof(format, v...)
}

func (m sqlMigrationLogger) Verbose() bool {
return log.Logger().Level >= logrus.DebugLevel
func (m sqlMigrationLogger) Write(p []byte) (n int, err error) {
log.Logger().Info(string(p))
return len(p), nil
}
2 changes: 1 addition & 1 deletion storage/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ func Test_engine_sqlDatabase(t *testing.T) {
require.NoError(t, row.Err())
var count int
assert.NoError(t, row.Scan(&count))
assert.Equal(t, 2, count)
assert.Equal(t, 1, count)
})
}
5 changes: 0 additions & 5 deletions storage/sql_migrations/001_initial.sql

This file was deleted.

0 comments on commit 6ab2cdc

Please sign in to comment.