Skip to content

Commit

Permalink
Upgrade pgx to v5
Browse files Browse the repository at this point in the history
Use trimmed sql-migrate
Config and db creation refactor.
  • Loading branch information
sesposito committed May 23, 2024
1 parent e07560b commit 9ab405e
Show file tree
Hide file tree
Showing 522 changed files with 35,893 additions and 52,307 deletions.
30 changes: 13 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ module github.com/heroiclabs/nakama/v3
go 1.21

require (
github.com/bits-and-blooms/bitset v1.12.0
github.com/blugelabs/bluge v0.2.2
github.com/blugelabs/bluge_segment_api v0.2.0
github.com/blugelabs/query_string v0.3.0
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204
github.com/go-gorp/gorp/v3 v3.1.0
github.com/gofrs/uuid/v5 v5.0.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/snappy v0.0.4
github.com/gorilla/handlers v1.5.2
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1
github.com/heroiclabs/nakama-common v1.31.1-0.20240523162557-752591b5e150
github.com/jackc/pgconn v1.14.1
github.com/heroiclabs/sql-migrate v0.0.0-20230615133120-fb3ad977aaaf
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgtype v1.14.0
github.com/jackc/pgx/v4 v4.18.1
github.com/prometheus/client_golang v1.17.0
github.com/rubenv/sql-migrate v1.5.2
github.com/jackc/pgx/v5 v5.5.5
github.com/stretchr/testify v1.8.4
github.com/twmb/murmur3 v1.1.8
github.com/uber-go/tally/v4 v4.1.10
go.uber.org/atomic v1.11.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.17.0
golang.org/x/oauth2 v0.15.0
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0
google.golang.org/grpc v1.60.0
Expand All @@ -44,6 +37,7 @@ require (
github.com/RoaringBitmap/roaring v0.9.4 // indirect
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
github.com/blevesearch/mmap-go v1.0.4 // indirect
github.com/blevesearch/segment v0.9.0 // indirect
Expand All @@ -59,22 +53,24 @@ require (
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/klauspost/compress v1.15.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/twmb/murmur3 v1.1.5 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
200 changes: 19 additions & 181 deletions go.sum

Large diffs are not rendered by default.

55 changes: 40 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ import (
"github.com/heroiclabs/nakama/v3/migrate"
"github.com/heroiclabs/nakama/v3/server"
"github.com/heroiclabs/nakama/v3/social"
_ "github.com/jackc/pgx/v4/stdlib"
"github.com/jackc/pgx/v5/stdlib"
_ "github.com/jackc/pgx/v5/stdlib" // Blank import to register SQL driver
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/protobuf/encoding/protojson"

_ "github.com/bits-and-blooms/bitset"
_ "github.com/go-gorp/gorp/v3"
_ "github.com/golang/snappy"
_ "github.com/prometheus/client_golang/prometheus"
_ "github.com/twmb/murmur3"
)

const cookieFilename = ".cookie"
Expand Down Expand Up @@ -71,13 +66,34 @@ func main() {

tmpLogger := server.NewJSONLogger(os.Stdout, zapcore.InfoLevel, server.JSONFormat)

ctx, ctxCancelFn := context.WithCancel(context.Background())

if len(os.Args) > 1 {
switch os.Args[1] {
case "--version":
fmt.Println(semver)
return
case "migrate":
migrate.Parse(os.Args[2:], tmpLogger)
config := server.ParseArgs(tmpLogger, os.Args[2:])
config.ValidateDatabase(tmpLogger)
db := server.DbConnect(ctx, tmpLogger, config, true)
defer db.Close()

conn, err := db.Conn(ctx)
if err != nil {
tmpLogger.Fatal("Failed to acquire db conn for migration", zap.Error(err))
}

if err = conn.Raw(func(driverConn any) error {
pgxConn := driverConn.(*stdlib.Conn).Conn()
migrate.RunCmd(ctx, tmpLogger, pgxConn, os.Args[2], config.GetLimit(), config.GetLogger().Format)

return nil
}); err != nil {
conn.Close()
tmpLogger.Fatal("Failed to acquire pgx conn for migration", zap.Error(err))
}
conn.Close()
return
case "check":
// Parse any command line args to look up runtime path.
Expand Down Expand Up @@ -108,7 +124,7 @@ func main() {

config := server.ParseArgs(tmpLogger, os.Args)
logger, startupLogger := server.SetupLogging(tmpLogger, config)
configWarnings := server.CheckConfig(logger, config)
configWarnings := config.Validate(logger)

startupLogger.Info("Nakama starting")
startupLogger.Info("Node", zap.String("name", config.GetName()), zap.String("version", semver), zap.String("runtime", runtime.Version()), zap.Int("cpu", runtime.NumCPU()), zap.Int("proc", runtime.GOMAXPROCS(0)))
Expand All @@ -125,14 +141,23 @@ func main() {
}
startupLogger.Info("Database connections", zap.Strings("dsns", redactedAddresses))

// Global server context.
ctx, ctxCancelFn := context.WithCancel(context.Background())

db, dbVersion := server.DbConnect(ctx, startupLogger, config)
startupLogger.Info("Database information", zap.String("version", dbVersion))
db := server.DbConnect(ctx, startupLogger, config, false)

// Check migration status and fail fast if the schema has diverged.
migrate.StartupCheck(startupLogger, db)
conn, err := db.Conn(context.Background())
if err != nil {
logger.Fatal("Failed to acquire db conn for migration check", zap.Error(err))
}

if err = conn.Raw(func(driverConn any) error {
pgxConn := driverConn.(*stdlib.Conn).Conn()
migrate.Check(ctx, startupLogger, pgxConn)
return nil
}); err != nil {
conn.Close()
logger.Fatal("Failed to acquire pgx conn for migration check", zap.Error(err))
}
conn.Close()

// Access to social provider integrations.
socialClient := social.NewClient(logger, 5*time.Second, config.GetGoogleAuth().OAuthConfig)
Expand Down
Loading

0 comments on commit 9ab405e

Please sign in to comment.