-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func fetchVariable(ctx context.Context, db *sql.DB, name string) (string, error) { | ||
row := db.QueryRowContext(ctx, "SHOW VARIABLES WHERE variable_name = ?", name) | ||
if row.Err() != nil { | ||
return "", fmt.Errorf("failed to query for %q variable: %w", name, row.Err()) | ||
} | ||
|
||
var variableName string | ||
var value string | ||
if err := row.Scan(&variableName, &value); err != nil { | ||
return "", fmt.Errorf("failed to scan row: %w", err) | ||
} else if variableName != name { | ||
return "", fmt.Errorf("the variable %q was returned instead of %q", variableName, name) | ||
} | ||
|
||
return value, nil | ||
} | ||
|
||
func ValidateMySQL(ctx context.Context, db *sql.DB, validateStreaming bool, validateGTID bool) error { | ||
requiredVariableToValueMap := make(map[string]string) | ||
if validateStreaming { | ||
requiredVariableToValueMap["binlog_format"] = "ROW" | ||
} | ||
|
||
if validateGTID { | ||
requiredVariableToValueMap["gtid_mode"] = "ON" | ||
requiredVariableToValueMap["enforce_gtid_consistency"] = "ON" | ||
} | ||
|
||
for requiredVariable, requiredValue := range requiredVariableToValueMap { | ||
value, err := fetchVariable(ctx, db, requiredVariable) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if strings.ToUpper(value) != requiredValue { | ||
return fmt.Errorf("%s must be set to %q, current value is %q", requiredVariable, requiredValue, value) | ||
} | ||
} | ||
|
||
return nil | ||
} |