Skip to content
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

Fix/codes #46

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions core/entmigrates/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"github.com/pubgo/funk/generic"
"github.com/pubgo/funk/log"
"github.com/pubgo/funk/version"
"github.com/testcontainers/testcontainers-go"

Check failure on line 22 in core/entmigrates/migrate.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/testcontainers/testcontainers-go (-: # github.com/testcontainers/testcontainers-go
"github.com/testcontainers/testcontainers-go/modules/postgres"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/urfave/cli/v3"
Expand Down Expand Up @@ -118,7 +118,7 @@
}

now := time.Now()
name := fmt.Sprintf("sql%d", now.UnixNano())
name := fmt.Sprintf("sql%s", now.Format("20060102150405"))
filename := fmt.Sprintf("%s.sql", name)
assert.Must(os.MkdirAll(g.config.MigrationPath, 0o755))
filename = filepath.Join(g.config.MigrationPath, filename)
Expand All @@ -127,20 +127,20 @@
return err
}

mmPkg := "github.com/pubgo/chameleon/internal/components/migrates"
mmPkg := "github.com/pubgo/lava/core/entmigrates"
genFile := jen.NewFile("migrations")
genFile.HeaderComment("DO NOT EDIT, THIS FILE IS GENERATED BY ENTORMIGRATE.")
genFile.HeaderComment("DO NOT EDIT, THIS FILE IS GENERATED BY ENTORMIGRATE.")
genFile.HeaderComment("DO NOT EDIT, THIS FILE IS GENERATED BY ENTORMIGRATE.")
genFile.Line()
genFile.Anon("embed")
genFile.ImportName(mmPkg, "migrates")
genFile.ImportName(mmPkg, "entmigrates")
genFile.Commentf("//go:embed %s.sql", name)
genFile.Var().Id(fmt.Sprintf("%sData string", name))
genFile.Var().Id("_").Qual(mmPkg, "Migration")
genFile.Id(fmt.Sprintf(`
func %s() *migrates.Migration {
return &migrates.Migration{
func %s() *entmigrates.Migration {
return &entmigrates.Migration{
Name: "%s",
Description: "%s",
MigrationSql: %sData,
Expand Down Expand Up @@ -185,44 +185,44 @@
Name: "migrate",
Usage: "migrate database schema",
Commands: []*cli.Command{
&cli.Command{
{
Name: "migrate",
Usage: "migrate all migrations",
Action: func(ctx context.Context, command *cli.Command) error {
return g.Migrate()
},
},
&cli.Command{
{
Name: "migrate_to",
Usage: "migrate_to <name>",
UsageText: "migrate migrate_to <name>",
Action: func(ctx context.Context, c *cli.Command) error {
return g.MigrateTo(c.Args().First())
},
},
&cli.Command{
{
Name: "rollback",
Usage: "rollback last migration",
Action: func(ctx context.Context, command *cli.Command) error {
return g.RollbackLast()
},
},
&cli.Command{
{
Name: "rollback_to",
Usage: "rollback_to <name>",
Action: func(ctx context.Context, c *cli.Command) error {
return g.RollbackTo(c.Args().First())
},
},

&cli.Command{
{
Name: "create",
Usage: "create migration",
Action: func(ctx context.Context, command *cli.Command) error {
return g.Create(g.tables)
},
},
&cli.Command{
{
Name: "list",
Usage: "list all migrations",
Action: func(ctx context.Context, command *cli.Command) error {
Expand Down Expand Up @@ -369,8 +369,8 @@
WithStartupTimeout(30 * time.Second)

ctr := assert.Must1(postgres.RunContainer(ctx,
testcontainers.WithImage("postgres:"+ver),

Check failure on line 372 in core/entmigrates/migrate.go

View workflow job for this annotation

GitHub Actions / lint

undefined: testcontainers (typecheck)
testcontainers.WithWaitStrategy(waitForLogs),

Check failure on line 373 in core/entmigrates/migrate.go

View workflow job for this annotation

GitHub Actions / lint

undefined: testcontainers (typecheck)
))

return assert.Must1(ctr.ConnectionString(ctx, "sslmode=disable"))
Expand Down
5 changes: 2 additions & 3 deletions servers/grpcs/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/rs/xid"
"github.com/valyala/fasthttp"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"

Expand Down Expand Up @@ -161,7 +160,7 @@ func handlerUnaryMiddle(middlewares map[string][]lava.Middleware) grpc.UnaryServ

if pb.Code.Code == 0 {
pb.Code.StatusCode = errorpb.Code_Internal
pb.Code.Code = int32(errutil.GrpcCodeToHTTP(codes.Code(uint32(errorpb.Code_Internal))))
pb.Code.Code = int32(errorpb.Code_Internal)
}

return nil, errutil.ConvertErr2Status(pb).Err()
Expand Down Expand Up @@ -266,7 +265,7 @@ func handlerStreamMiddle(middlewares map[string][]lava.Middleware) grpc.StreamSe
}

if pb.Code.Code == 0 {
pb.Code.Code = int32(errutil.GrpcCodeToHTTP(codes.Code(pb.Code.StatusCode)))
pb.Code.Code = int32(errorpb.Code_Internal)
pb.Code.StatusCode = errorpb.Code_Internal
}

Expand Down
6 changes: 3 additions & 3 deletions servers/grpcs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (s *serviceImpl) DixInject(
pb = &errorpb.ErrCode{
Message: err.Error(),
StatusCode: errorpb.Code_Internal,
Code: 500,
Code: int32(errorpb.Code_Internal),
Name: "lava.grpc.status",
}
} else {
Expand All @@ -280,15 +280,15 @@ func (s *serviceImpl) DixInject(
} else {
pb = &errorpb.ErrCode{
Message: sts.Message(),
Code: 500,
Code: int32(errorpb.Code(sts.Code())),
StatusCode: errorpb.Code(sts.Code()),
Name: "lava.grpc.status",
Details: sts.Proto().Details,
}
}
}

const fallback = `{"code":500, "name":"lava.grpc.status", "status_code": 13, "message": "failed to marshal error message"}`
const fallback = `{"code":13, "name":"lava.grpc.status", "status_code": 500, "message": "failed to marshal error message"}`

// skip error
if pb.StatusCode == errorpb.Code_OK {
Expand Down
Loading