Commit 67feaa83 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

DB version output. Merge #127

parent cae2261f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -9,6 +9,12 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
- Add User-Agent to the default list of accepted CORS request headers.
- Improve how the dashboard component is stopped when server shuts down.
- Improve dashboard CORS support by extending the list of allowed request headers.
- Server startup output now contains database version string.
- Migrate command output now contains database version string.
- Doctor command output now contains database version string.

### Changed
- Internal operations exposed to the script runtime through function bindings now silently ignore unknown parameters.

## [1.2.0] - 2017-11-06
### Added
+1 −2
Original line number Diff line number Diff line
@@ -146,8 +146,7 @@ dbsetup:
	./${BUILDDIR}/dev/${BINNAME} migrate up

.PHONY: dbreset
dbreset:
	./${BUILDDIR}/dev/${BINNAME} migrate down --limit 0
dbreset: dbstop $(shell rm -rf /tmp/cockroach) dbstart

.PHONY: dockerbuild
dockerbuild:
+6 −0
Original line number Diff line number Diff line
@@ -126,6 +126,12 @@ func MigrateParse(args []string, logger *zap.Logger) {
		logger.Fatal("Error pinging database", zap.Error(err))
	}

	var dbVersion string
	if err = db.QueryRow("SELECT version()").Scan(&dbVersion); err != nil {
		logger.Fatal("Error querying database version", zap.Error(err))
	}
	logger.Info("Database information", zap.String("version", dbVersion))

	var exists bool
	err = db.QueryRow("SELECT EXISTS(SELECT 1 FROM pg_database WHERE datname = $1)", dbname).Scan(&exists)
start:
+10 −4
Original line number Diff line number Diff line
@@ -81,7 +81,8 @@ func main() {
	multiLogger.Info("Data directory", zap.String("path", config.GetDataDir()))
	multiLogger.Info("Database connections", zap.Strings("dsns", config.GetDatabase().Addresses))

	db := dbConnect(multiLogger, config.GetDatabase().Addresses)
	db, dbVersion := dbConnect(multiLogger, config.GetDatabase().Addresses)
	multiLogger.Info("Database information", zap.String("version", dbVersion))

	// Check migration status and log if the schema has diverged.
	cmd.MigrationStartupCheck(multiLogger, db)
@@ -114,7 +115,7 @@ func main() {
	purchaseService := server.NewPurchaseService(jsonLogger, multiLogger, db, config.GetPurchase())
	pipeline := server.NewPipeline(config, db, trackerService, matchmakerService, messageRouter, sessionRegistry, socialClient, runtimePool, purchaseService, notificationService)
	authService := server.NewAuthenticationService(jsonLogger, config, db, jsonpbMarshaler, jsonpbUnmarshaler, statsService, sessionRegistry, socialClient, pipeline, runtimePool)
	dashboardService := server.NewDashboardService(jsonLogger, multiLogger, semver, config, statsService)
	dashboardService := server.NewDashboardService(jsonLogger, multiLogger, semver, dbVersion, config, statsService)

	gaenabled := len(os.Getenv("NAKAMA_TELEMETRY")) < 1
	cookie := newOrLoadCookie(config.GetDataDir())
@@ -148,7 +149,7 @@ func main() {
	select {}
}

func dbConnect(multiLogger *zap.Logger, dsns []string) *sql.DB {
func dbConnect(multiLogger *zap.Logger, dsns []string) (*sql.DB, string) {
	// TODO config database pooling
	rawurl := fmt.Sprintf("postgresql://%s?sslmode=disable", dsns[0])
	url, err := url.Parse(rawurl)
@@ -169,7 +170,12 @@ func dbConnect(multiLogger *zap.Logger, dsns []string) *sql.DB {
		multiLogger.Fatal("Error pinging database", zap.Error(err))
	}

	return db
	var dbVersion string
	if err := db.QueryRow("SELECT version()").Scan(&dbVersion); err != nil {
		multiLogger.Fatal("Error querying database version", zap.Error(err))
	}

	return db, dbVersion
}

// Help improve Nakama by sending anonymous usage statistics.
+9 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import (
type dashboardService struct {
	logger              *zap.Logger
	version             string
	dbVersion           string
	config              Config
	statsService        StatsService
	httpServer          *http.Server
@@ -41,10 +42,11 @@ type dashboardService struct {
}

// NewDashboardService creates a new dashboardService
func NewDashboardService(logger *zap.Logger, multiLogger *zap.Logger, version string, config Config, statsService StatsService) *dashboardService {
func NewDashboardService(logger *zap.Logger, multiLogger *zap.Logger, version string, dbVersion string, config Config, statsService StatsService) *dashboardService {
	service := &dashboardService{
		logger:       logger,
		version:      version,
		dbVersion:    dbVersion,
		config:       config,
		statsService: statsService,
		mux:          mux.NewRouter(),
@@ -107,6 +109,7 @@ func (s *dashboardService) infoHandler(w http.ResponseWriter, r *http.Request) {

	info := map[string]interface{}{
		"version":    s.version,
		"db_version": s.dbVersion,
		"go":         runtime.Version(),
		"arch":       runtime.GOARCH,
		"os":         runtime.GOOS,
Loading