Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sesposito committed May 23, 2024
1 parent 9ab405e commit 67e6996
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 9 additions & 1 deletion migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"github.com/heroiclabs/nakama/v3/server"
sqlmigrate "github.com/heroiclabs/sql-migrate"
"github.com/jackc/pgx/v5"
_ "github.com/jackc/pgx/v5/stdlib" // Blank import to register SQL driver
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

_ "github.com/jackc/pgx/v5/stdlib" // Blank import to register SQL driver
)

const (
Expand Down Expand Up @@ -62,6 +63,7 @@ func Check(ctx context.Context, logger *zap.Logger, db *pgx.Conn) {
if err != nil {
logger.Fatal("Could not find migrations", zap.Error(err))
}

records, err := sqlmigrate.GetMigrationRecords(ctx, db)
if err != nil {
logger.Fatal("Could not get migration records, run `nakama migrate up`", zap.Error(err))
Expand Down Expand Up @@ -104,6 +106,8 @@ func (ms *migrationService) up(ctx context.Context, logger *zap.Logger, db *pgx.
ms.limit = 0
}

logger.Info("Applying database migrations", zap.Int("limit", ms.limit))

appliedMigrations, err := sqlmigrate.ExecMax(ctx, db, ms.migrations, sqlmigrate.Up, ms.limit)
if err != nil {
logger.Fatal("Failed to apply migrations", zap.Int("count", appliedMigrations), zap.Error(err))
Expand All @@ -117,6 +121,8 @@ func (ms *migrationService) down(ctx context.Context, logger *zap.Logger, db *pg
ms.limit = 1
}

logger.Info("Reverting database migrations", zap.Int("limit", ms.limit))

appliedMigrations, err := sqlmigrate.ExecMax(ctx, db, ms.migrations, sqlmigrate.Down, ms.limit)
if err != nil {
logger.Fatal("Failed to migrate back", zap.Int("count", appliedMigrations), zap.Error(err))
Expand All @@ -130,6 +136,8 @@ func (ms *migrationService) redo(ctx context.Context, logger *zap.Logger, db *pg
logger.Warn("Limit is ignored when redo is invoked")
}

logger.Info("Reapplying database migrations", zap.Int("limit", ms.limit))

appliedMigrations, err := sqlmigrate.ExecMax(ctx, db, ms.migrations, sqlmigrate.Down, 1)
if err != nil {
logger.Fatal("Failed to migrate back", zap.Int("count", appliedMigrations), zap.Error(err))
Expand Down
7 changes: 3 additions & 4 deletions server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ var (
}
metrics = NewLocalMetrics(logger, logger, nil, cfg)
storageIdx, _ = NewLocalStorageIndex(logger, nil, &StorageConfig{DisableIndexOnly: false}, metrics)
_ = CheckConfig(logger, cfg)
_ = ValidateConfig(logger, cfg)
_ = cfg.Validate(logger)
)

type DummyMessageRouter struct{}
Expand Down Expand Up @@ -172,8 +171,8 @@ func NewConsoleLogger(output *os.File, verbose bool) *zap.Logger {
}

func NewDB(t *testing.T) *sql.DB {
//dbUrl := "postgresql://postgres@127.0.0.1:5432/nakama?sslmode=disable"
dbUrl := "postgresql://root@127.0.0.1:26257/nakama?sslmode=disable"
dbUrl := "postgresql://postgres@127.0.0.1:5432/nakama?sslmode=disable"
//dbUrl := "postgresql://root@127.0.0.1:26257/nakama?sslmode=disable"
if dbUrlEnv := os.Getenv("TEST_DB_URL"); len(dbUrlEnv) > 0 {
dbUrl = dbUrlEnv
}
Expand Down

0 comments on commit 67e6996

Please sign in to comment.