-
Notifications
You must be signed in to change notification settings - Fork 892
feat(examples): Use hosted MySQL databases for tests #2982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
25b5d7d
feat(examples): Use hosted MySQL databases for tests
kyleconroy b60edb7
Fix the tests
kyleconroy beda61a
Fix db_test.go (again)
kyleconroy 0017dba
Add queryset names
kyleconroy 7b80a01
feat(vet): Allow managed databases for MySQL
kyleconroy 21170b7
import mysql driver
kyleconroy 4f5cfed
Remove MySQL Github service
kyleconroy 35c9ffd
Remove MySQL migration from vet_test
kyleconroy 572744c
Switch to managed mode for more examples
kyleconroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
package quickdb | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// The database URI returned by the QuickDB service isn't understood by the | ||
// go-mysql-driver | ||
func MySQLReformatURI(original string) (string, error) { | ||
u, err := url.Parse(original) | ||
if err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("%s@tcp(%s)%s?multiStatements=true&parseTime=true&tls=true", u.User, u.Host, u.Path), nil | ||
} |
This file contains hidden or 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,27 @@ | ||
package hosted | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
"github.com/sqlc-dev/sqlc/internal/quickdb" | ||
pb "github.com/sqlc-dev/sqlc/internal/quickdb/v1" | ||
) | ||
|
||
var client pb.QuickClient | ||
var once sync.Once | ||
|
||
func initClient() error { | ||
projectID := os.Getenv("CI_SQLC_PROJECT_ID") | ||
authToken := os.Getenv("CI_SQLC_AUTH_TOKEN") | ||
if projectID == "" || authToken == "" { | ||
return fmt.Errorf("missing project id or auth token") | ||
} | ||
c, err := quickdb.NewClient(projectID, authToken) | ||
if err != nil { | ||
return err | ||
} | ||
client = c | ||
return nil | ||
} |
This file contains hidden or 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,64 @@ | ||
package hosted | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/sqlc-dev/sqlc/internal/quickdb" | ||
pb "github.com/sqlc-dev/sqlc/internal/quickdb/v1" | ||
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath" | ||
) | ||
|
||
func MySQL(t *testing.T, migrations []string) string { | ||
ctx := context.Background() | ||
t.Helper() | ||
|
||
once.Do(func() { | ||
if err := initClient(); err != nil { | ||
t.Log(err) | ||
} | ||
}) | ||
|
||
if client == nil { | ||
t.Skip("client init failed") | ||
} | ||
|
||
var seed []string | ||
files, err := sqlpath.Glob(migrations) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, f := range files { | ||
blob, err := os.ReadFile(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
seed = append(seed, string(blob)) | ||
} | ||
|
||
resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ | ||
Engine: "mysql", | ||
Region: quickdb.GetClosestRegion(), | ||
Migrations: seed, | ||
}) | ||
if err != nil { | ||
t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err) | ||
} | ||
|
||
t.Cleanup(func() { | ||
_, err = client.DropEphemeralDatabase(ctx, &pb.DropEphemeralDatabaseRequest{ | ||
DatabaseId: resp.DatabaseId, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
uri, err := quickdb.MySQLReformatURI(resp.Uri) | ||
if err != nil { | ||
t.Fatalf("uri error: %s", err) | ||
} | ||
|
||
return uri | ||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might still want to bail early if the engine is sqlite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to let the client make the request and fail so that it's easier to add engine support at the server without a client change.