Skip to content

Commit

Permalink
Remove timeout from MySQL migrations (mattermost-community#2974)
Browse files Browse the repository at this point in the history
(cherry picked from commit c08ce96)
  • Loading branch information
mgdelacroix authored and mattermost-build committed Apr 28, 2022
1 parent 299a780 commit 5b243c8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion server/services/store/sqlstore/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,29 @@ func appendMultipleStatementsFlag(connectionString string) (string, error) {
return config.FormatDSN(), nil
}

// resetReadTimeout removes the timeout contraint from the MySQL dsn.
func resetReadTimeout(dataSource string) (string, error) {
config, err := mysqldriver.ParseDSN(dataSource)
if err != nil {
return "", err
}
config.ReadTimeout = 0
return config.FormatDSN(), nil
}

// migrations in MySQL need to run with the multiStatements flag
// enabled, so this method creates a new connection ensuring that it's
// enabled.
func (s *SQLStore) getMigrationConnection() (*sql.DB, error) {
connectionString := s.connectionString
if s.dbType == model.MysqlDBType {
var err error
connectionString, err = appendMultipleStatementsFlag(s.connectionString)
connectionString, err = resetReadTimeout(connectionString)
if err != nil {
return nil, err
}

connectionString, err = appendMultipleStatementsFlag(connectionString)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5b243c8

Please sign in to comment.