Skip to content

Commit

Permalink
feat(vet): Use new dbmanager client (sqlc-dev#3423)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored and lisitsky committed Jun 21, 2024
1 parent 0e1d754 commit 33b5e1c
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions internal/cmd/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"google.golang.org/protobuf/encoding/protojson"

"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/dbmanager"
"github.com/sqlc-dev/sqlc/internal/debug"
"github.com/sqlc-dev/sqlc/internal/migrations"
"github.com/sqlc-dev/sqlc/internal/opts"
"github.com/sqlc-dev/sqlc/internal/plugin"
"github.com/sqlc-dev/sqlc/internal/quickdb"
pb "github.com/sqlc-dev/sqlc/internal/quickdb/v1"
"github.com/sqlc-dev/sqlc/internal/shfmt"
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
"github.com/sqlc-dev/sqlc/internal/vet"
Expand Down Expand Up @@ -386,7 +386,7 @@ type checker struct {
Env *cel.Env
Stderr io.Writer
OnlyManagedDB bool
Client pb.QuickClient
Client dbmanager.Client
Replacer *shfmt.Replacer
}

Expand All @@ -405,10 +405,7 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f

if c.Client == nil {
// FIXME: Eventual race condition
client, err := quickdb.NewClientFromConfig(c.Conf.Cloud)
if err != nil {
return "", cleanup, fmt.Errorf("managed: client: %w", err)
}
client := dbmanager.NewClient(c.Conf.Servers)
c.Client = client
}

Expand All @@ -425,22 +422,14 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f
ddl = append(ddl, migrations.RemoveIgnoredStatements(string(contents)))
}

resp, err := c.Client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
resp, err := c.Client.CreateDatabase(ctx, &dbmanager.CreateDatabaseRequest{
Engine: string(s.Engine),
Region: quickdb.GetClosestRegion(),
Migrations: ddl,
})
if err != nil {
return "", cleanup, fmt.Errorf("managed: create database: %w", err)
}

cleanup = func() error {
_, err := c.Client.DropEphemeralDatabase(ctx, &pb.DropEphemeralDatabaseRequest{
DatabaseId: resp.DatabaseId,
})
return err
}

var uri string
switch s.Engine {
case config.EngineMySQL:
Expand Down

0 comments on commit 33b5e1c

Please # to comment.