This repository has been archived by the owner on Jun 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 327
-lock-timeout option doesn't work with CockroachDB #314
Comments
In case anyone else is affected by this, you can easily migrate this by retrying. Here is my code, using backoff. func Migrate(dsn string, service string) DBSetupOpt {
return func(logger *logrus.Logger, _ *sql.DB) error {
if dsn == "" {
return errors.New("no dsn specified")
}
if service == "" {
return errors.New("no service specified")
}
// This is needed because the migrate tool recognizes 'postgres/postgresql'
// driver part of the DSN and applies the Postgres driver instead of the Cockroach one.
dsn = strings.Replace(dsn, "postgresql", "cockroach", 1)
dsn = strings.Replace(dsn, "postgres", "cockroach", 1)
sqlPath := filepath.Join(cli.GetProjectPath(),
fmt.Sprintf(sqlProjPathFmt, service))
logger.WithFields(logrus.Fields{"dsn": dsn, "sql-path": sqlPath}).Infoln("Running migrations")
var retry int
migrate := func() error {
err := cli.ForkDir(nil, []string{"migrate",
"-verbose",
"-database", dsn,
"-path", ".",
"up"},
sqlPath)
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
"retries": migrateRetries - retry,
}).Infoln("Retrying to run migrations")
retry++
}
return err
}
return backoff.Retry(migrate,
backoff.WithMaxTries(backoff.NewExponentialBackOff(), uint64(10)))
}
} As you can notice, I have to run the CLI command because I haven't managed to make migrations work by calling the library directly (complains about |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I came across this while launching multiple services at the same time (they run migrations on startup using the
migrate
cli, calling it from Go doesn't work for CRDB either but that's a different story).I replicated it by running up migrations at the same time in 2 different terminals.
The text was updated successfully, but these errors were encountered: