From 266e5e143e87519047b9be3202a0aba273b83de3 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Thu, 15 Dec 2022 10:52:40 -0500 Subject: [PATCH] chore: move migrator back to main so we dont need it in grpc server (#1224) --- cmd/flipt/main.go | 14 +++++++++++++- internal/cmd/grpc.go | 14 +------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/flipt/main.go b/cmd/flipt/main.go index 8d607e2ef6..073d71a764 100644 --- a/cmd/flipt/main.go +++ b/cmd/flipt/main.go @@ -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 } diff --git a/internal/cmd/grpc.go b/internal/cmd/grpc.go index fa11fa7967..b78693634f 100644 --- a/internal/cmd/grpc.go +++ b/internal/cmd/grpc.go @@ -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")) @@ -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)