Skip to content

Commit

Permalink
chore: move migrator back to main so we dont need it in grpc server (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Dec 15, 2022
1 parent f546cf8 commit 266e5e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 13 additions & 1 deletion cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,19 @@ func run(ctx context.Context, logger *zap.Logger) error {
})
}

grpcServer, err := cmd.NewGRPCServer(ctx, logger, forceMigrate, cfg)
migrator, err := sql.NewMigrator(*cfg, logger)
if err != nil {
return err
}

if err := migrator.Up(forceMigrate); err != nil {
migrator.Close()
return err
}

migrator.Close()

grpcServer, err := cmd.NewGRPCServer(ctx, logger, cfg)
if err != nil {
return err
}
Expand Down
14 changes: 1 addition & 13 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type GRPCServer struct {
func NewGRPCServer(
ctx context.Context,
logger *zap.Logger,
forceMigrate bool,
cfg *config.Config,
) (*GRPCServer, error) {
logger = logger.With(zap.String("server", "grpc"))
Expand All @@ -89,18 +88,7 @@ func NewGRPCServer(
cfg: cfg,
}

migrator, err := sql.NewMigrator(*cfg, logger)
if err != nil {
return nil, err
}

if err := migrator.Up(forceMigrate); err != nil {
migrator.Close()
return nil, err
}

migrator.Close()

var err error
server.ln, err = net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.GRPCPort))
if err != nil {
return nil, fmt.Errorf("creating grpc listener: %w", err)
Expand Down

0 comments on commit 266e5e1

Please sign in to comment.