Add MySQLProvider and register at startup#33
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request extends the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a MySQLProvider and registers it at startup. The implementation is mostly solid, but I have a few suggestions for improvement. Firstly, the error handling during provider registration in cmd/root.go uses panic, which is inconsistent with the project's typical error handling and not ideal for a command-line tool's user experience. I've suggested a more graceful exit. Secondly, the version validation for the new provider is a bit too lenient. I've recommended strengthening it to ensure version components are numeric and have also suggested updates to the test suite to cover these new validation rules.
| if err := mysqlprovider.Register(providers.DefaultRegistry); err != nil { | ||
| panic(fmt.Sprintf("failed to register MySQL provider: %v", err)) | ||
| } |
There was a problem hiding this comment.
Using panic for error handling during startup can be jarring for users of a CLI tool as it produces a stack trace. A more user-friendly approach is to print a clean error message to standard error and exit with a non-zero status code. This is also more consistent with error handling patterns seen elsewhere in the project.
| if err := mysqlprovider.Register(providers.DefaultRegistry); err != nil { | |
| panic(fmt.Sprintf("failed to register MySQL provider: %v", err)) | |
| } | |
| if err := mysqlprovider.Register(providers.DefaultRegistry); err != nil { | |
| fmt.Fprintf(os.Stderr, "failed to register MySQL provider: %v\n", err) | |
| os.Exit(1) | |
| } |
| func (p *MySQLProvider) ValidateVersion(version string) error { | ||
| parts := strings.Split(version, ".") | ||
| if len(parts) < 2 { | ||
| return fmt.Errorf("invalid MySQL version format: %q (expected X.Y or X.Y.Z)", version) | ||
| } | ||
| return nil | ||
| } |
There was a problem hiding this comment.
The current version validation only checks for the presence of at least one dot (.) in the version string. It doesn't ensure that the version components are numeric. This could lead to accepting invalid versions like "a.b" as valid. The validation should be strengthened to parse each component and verify it's a number. Note that you'll need to import the strconv package for this change.
func (p *MySQLProvider) ValidateVersion(version string) error {
parts := strings.Split(version, ".")
if len(parts) < 2 {
return fmt.Errorf("invalid MySQL version format: %q (expected X.Y or X.Y.Z)", version)
}
for _, part := range parts {
if _, err := strconv.Atoi(part); err != nil {
return fmt.Errorf("invalid numeric part in version string %q: %s", version, part)
}
}
return nil
}| {"8.4.4", false}, | ||
| {"9.1.0", false}, | ||
| {"5.7", false}, | ||
| {"invalid", true}, |
There was a problem hiding this comment.
The test suite for ValidateVersion can be improved by adding cases that test for non-numeric version components (e.g., "5.a") and empty components (e.g., from a trailing dot like "5.7."). This will help ensure the validation logic is robust against a wider range of invalid inputs, especially after strengthening the validation logic as suggested in mysql.go.
{"8.4.4", false},
{"9.1.0", false},
{"5.7", false},
{"invalid", true},
{"5.a", true},
{"a.5", true},
{"5.7.", true},There was a problem hiding this comment.
Pull request overview
Adds a new provider implementation for MySQL under the emerging providers abstraction and wires it into the application startup registry so it’s available by default.
Changes:
- Introduces
providers/mysqlwithMySQLProviderimplementingproviders.Provider(name, version validation, default port range). - Adds unit tests for the MySQL provider and its registry registration.
- Registers the MySQL provider into
providers.DefaultRegistryduring CLI initialization (cmd/root.go).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| providers/mysql/mysql.go | New MySQLProvider implementation (Name/ValidateVersion/DefaultPorts) and Register helper. |
| providers/mysql/mysql_test.go | Unit tests for provider name, version validation, and registration into a registry. |
| cmd/root.go | Registers the MySQL provider into providers.DefaultRegistry at startup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (p *MySQLProvider) ValidateVersion(version string) error { | ||
| parts := strings.Split(version, ".") | ||
| if len(parts) < 2 { | ||
| return fmt.Errorf("invalid MySQL version format: %q (expected X.Y or X.Y.Z)", version) | ||
| } | ||
| return nil |
There was a problem hiding this comment.
ValidateVersion currently only checks that the string has at least one dot, so many clearly invalid versions are accepted (e.g., "8", "8.0.", "8..0", "8.0.0.1", "8.x"). This makes the validation misleading and can allow bad inputs to propagate to later version/feature logic. Consider enforcing a numeric X.Y or X.Y.Z format (reject empty components and >3 segments), e.g. via a regexp or by parsing each component as an int after strings.TrimSpace.
| func TestMySQLProviderValidateVersion(t *testing.T) { | ||
| p := NewMySQLProvider() | ||
| tests := []struct { | ||
| version string | ||
| wantErr bool | ||
| }{ | ||
| {"8.4.4", false}, | ||
| {"9.1.0", false}, | ||
| {"5.7", false}, | ||
| {"invalid", true}, | ||
| } | ||
| for _, tt := range tests { | ||
| err := p.ValidateVersion(tt.version) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("ValidateVersion(%q) error = %v, wantErr %v", tt.version, err, tt.wantErr) | ||
| } | ||
| } |
There was a problem hiding this comment.
The ValidateVersion table test currently only covers one invalid case (no dots). Given the provider is meant to validate version strings, add cases that assert rejection of malformed-but-dotted inputs (e.g. trailing dot, empty component, extra component, non-numeric component) and acceptance of X.Y (e.g. "8.0"). This will prevent regressions once ValidateVersion is tightened.
|
|
||
| func init() { | ||
| if err := mysqlprovider.Register(providers.DefaultRegistry); err != nil { | ||
| panic(fmt.Sprintf("failed to register MySQL provider: %v", err)) |
There was a problem hiding this comment.
Using panic in init() will produce a stack trace if registration ever fails (e.g., duplicate registration), which is a user-facing behavior change compared to the rest of the CLI error handling (which typically prints a message and exits). Consider switching to a controlled exit path (e.g., common.Exitf(1, ...) or deferring provider registration to Execute() where errors can be returned/printed cleanly).
| panic(fmt.Sprintf("failed to register MySQL provider: %v", err)) | |
| common.Exitf(1, "failed to register MySQL provider: %v", err) |
Summary
MySQLProviderimplementing theProviderinterface with version validation and default port configuration (3306, 3 ports per instance)MySQLProviderat startup viaDefaultRegistryincmd/root.goinit()Test plan
go test ./providers/... -v-- all 7 tests pass (4 registry + 3 mysql provider)go buildsucceeds./dbdeployer --versionruns without panicCloses #26
Closes #27