(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string)
| 62 | } |
| 63 | |
| 64 | func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string) (string, error) { |
| 65 | versionQuery := `select @@global.version` |
| 66 | |
| 67 | var version string |
| 68 | if err := db.QueryRow(versionQuery).Scan(&version); err != nil { |
| 69 | return "", err |
| 70 | } |
| 71 | |
| 72 | if migrationContext.SkipPortValidation { |
| 73 | return version, nil |
| 74 | } |
| 75 | |
| 76 | var extraPort int |
| 77 | |
| 78 | extraPortQuery := `select @@global.extra_port` |
| 79 | if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil { //nolint:staticcheck |
| 80 | // swallow this error. not all servers support extra_port |
| 81 | } |
| 82 | |
| 83 | // AliyunRDS set users port to "NULL", replace it by gh-ost param |
| 84 | // GCP set users port to "NULL", replace it by gh-ost param |
| 85 | // Azure MySQL set users port to a different value by design, replace it by gh-ost para |
| 86 | var port int |
| 87 | if migrationContext.AliyunRDS || migrationContext.GoogleCloudPlatform || migrationContext.AzureMySQL { |
| 88 | port = connectionConfig.Key.Port |
| 89 | } else { |
| 90 | portQuery := `select @@global.port` |
| 91 | if err := db.QueryRow(portQuery).Scan(&port); err != nil { |
| 92 | return "", err |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) { |
| 97 | migrationContext.Log.Infof("%s connection validated on %+v", name, connectionConfig.Key) |
| 98 | return version, nil |
| 99 | } else if extraPort == 0 { |
| 100 | return "", fmt.Errorf("unexpected database port reported: %+v", port) |
| 101 | } else { |
| 102 | return "", fmt.Errorf("unexpected database port reported: %+v / extra_port: %+v", port, extraPort) |
| 103 | } |
| 104 | } |
no test coverage detected
searching dependent graphs…