Update morph dependecy to fix a data race (#19326)

* Update morph dependecy to fix a data race

* run go mod tidy
This commit is contained in:
Ibrahim Serdar Acikgoz
2022-01-13 12:41:56 +03:00
committed by GitHub
parent 73d7b24745
commit 73ac1a354d
8 changed files with 38 additions and 33 deletions

2
go.mod
View File

@@ -29,7 +29,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1
github.com/getsentry/sentry-go v0.11.0
github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect
github.com/go-morph/morph v0.2.1
github.com/go-morph/morph v0.2.2
github.com/go-redis/redis/v8 v8.11.4 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-sql-driver/mysql v1.6.0

8
go.sum
View File

@@ -527,12 +527,8 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-morph/morph v0.0.0-20211202070306-dbdc0736c17e h1:iS/jL0Xij+6O5d/VXrt+VOZfATHCTDIjBVVthVpHFY0=
github.com/go-morph/morph v0.0.0-20211202070306-dbdc0736c17e/go.mod h1:XQh5WcM351wOV3z3zEWRM8RaJ65E2p4P7WWbmFAi8x4=
github.com/go-morph/morph v0.0.0-20220110203813-7e65a95885ea h1:l2xnsVP6YW9DZet6HfUhMKtEOPyGg2QsRyDPLECnW1o=
github.com/go-morph/morph v0.0.0-20220110203813-7e65a95885ea/go.mod h1:XQh5WcM351wOV3z3zEWRM8RaJ65E2p4P7WWbmFAi8x4=
github.com/go-morph/morph v0.2.1 h1:Wo+TUt4+jCwKJh57mpuRBSMioYjA2TwjQD027hhOgro=
github.com/go-morph/morph v0.2.1/go.mod h1:XQh5WcM351wOV3z3zEWRM8RaJ65E2p4P7WWbmFAi8x4=
github.com/go-morph/morph v0.2.2 h1:f7/+VZ+1/eR+5SUoMKYo16QQISewuvS4hogX8x/uFnA=
github.com/go-morph/morph v0.2.2/go.mod h1:XQh5WcM351wOV3z3zEWRM8RaJ65E2p4P7WWbmFAi8x4=
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=

View File

@@ -16,13 +16,6 @@ import (
const driverName = "mysql"
const defaultMigrationMaxSize = 10 * 1 << 20 // 10 MB
var defaultConfig = &Config{
Config: drivers.Config{
MigrationsTable: "db_migrations",
StatementTimeoutInSecs: 60,
MigrationMaxSize: defaultMigrationMaxSize,
},
}
// add here any custom driver configuration
var configParams = []string{
@@ -44,7 +37,7 @@ type mysql struct {
}
func WithInstance(dbInstance *sql.DB, config *Config) (drivers.Driver, error) {
driverConfig := mergeConfigs(config, defaultConfig)
driverConfig := mergeConfigs(config, getDefaultConfig())
conn, err := dbInstance.Conn(context.Background())
if err != nil {
@@ -69,7 +62,7 @@ func Open(connURL string) (drivers.Driver, error) {
return nil, &drivers.AppError{Driver: driverName, OrigErr: err, Message: "failed to sanitize url from custom parameters"}
}
driverConfig, err := mergeConfigWithParams(customParams, defaultConfig)
driverConfig, err := mergeConfigWithParams(customParams, getDefaultConfig())
if err != nil {
return nil, &drivers.AppError{Driver: driverName, OrigErr: err, Message: "failed to merge custom params to driver config"}
}

View File

@@ -1,6 +1,7 @@
package mysql
import (
"github.com/go-morph/morph/drivers"
mysqlDriver "github.com/go-sql-driver/mysql"
)
@@ -21,3 +22,13 @@ func extractDatabaseNameFromURL(conn string) (string, error) {
return cfg.DBName, nil
}
func getDefaultConfig() *Config {
return &Config{
Config: drivers.Config{
MigrationsTable: "db_migrations",
StatementTimeoutInSecs: 60,
MigrationMaxSize: defaultMigrationMaxSize,
},
}
}

View File

@@ -14,14 +14,7 @@ import (
)
var (
driverName = "postgres"
defaultConfig = &Config{
Config: drivers.Config{
MigrationsTable: "db_migrations",
StatementTimeoutInSecs: 60,
MigrationMaxSize: defaultMigrationMaxSize,
},
}
driverName = "postgres"
defaultMigrationMaxSize = 10 * 1 << 20 // 10 MB
configParams = []string{
"x-migration-max-size",
@@ -44,7 +37,7 @@ type postgres struct {
}
func WithInstance(dbInstance *sql.DB, config *Config) (drivers.Driver, error) {
driverConfig := mergeConfigs(config, defaultConfig)
driverConfig := mergeConfigs(config, getDefaultConfig())
conn, err := dbInstance.Conn(context.Background())
if err != nil {
@@ -77,7 +70,7 @@ func Open(connURL string) (drivers.Driver, error) {
return nil, &drivers.AppError{Driver: driverName, OrigErr: err, Message: "failed to sanitize url from custom parameters"}
}
driverConfig, err := mergeConfigWithParams(customParams, defaultConfig)
driverConfig, err := mergeConfigWithParams(customParams, getDefaultConfig())
if err != nil {
return nil, &drivers.AppError{Driver: driverName, OrigErr: err, Message: "failed to merge custom params to driver config"}
}

View File

@@ -1,6 +1,10 @@
package postgres
import "net/url"
import (
"net/url"
"github.com/go-morph/morph/drivers"
)
func extractDatabaseNameFromURL(URL string) (string, error) {
uri, err := url.Parse(URL)
@@ -10,3 +14,13 @@ func extractDatabaseNameFromURL(URL string) (string, error) {
return uri.Path[1:], nil
}
func getDefaultConfig() *Config {
return &Config{
Config: drivers.Config{
MigrationsTable: "db_migrations",
StatementTimeoutInSecs: 60,
MigrationMaxSize: defaultMigrationMaxSize,
},
}
}

View File

@@ -42,10 +42,6 @@ type Config struct {
type EngineOption func(*Morph)
var defaultConfig = &Config{
Logger: log.New(os.Stderr, "", log.LstdFlags), // add default logger
}
func WithLogger(logger *log.Logger) EngineOption {
return func(m *Morph) {
m.config.Logger = logger
@@ -82,7 +78,9 @@ func WithLock(key string) EngineOption {
// New creates a new instance of the migrations engine from an existing db instance and a migrations source.
func New(ctx context.Context, driver drivers.Driver, source sources.Source, options ...EngineOption) (*Morph, error) {
engine := &Morph{
config: defaultConfig,
config: &Config{
Logger: log.New(os.Stderr, "", log.LstdFlags), // add default logger
},
source: source,
driver: driver,
}

2
vendor/modules.txt vendored
View File

@@ -214,7 +214,7 @@ github.com/gigawattio/window
# github.com/go-asn1-ber/asn1-ber v1.5.3
## explicit
github.com/go-asn1-ber/asn1-ber
# github.com/go-morph/morph v0.2.1
# github.com/go-morph/morph v0.2.2
## explicit
github.com/go-morph/morph
github.com/go-morph/morph/drivers