Commit 1b73de79 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

DB updates for constraints

parent 94fc95e5
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).

## [Unreleased]
### Changed
- Nakama will now log an error and refuse to start if the schema is outdated.
- Drop unused leaderboard 'next' and 'previous' fields.
- A user's 'last online at' field now contains a current UTC milliseconds timestamp if they are currently online.
- Storage remove operations now ignore records that don't exist.
- Fields that expect JSON content now allow up to 32kb of data.

## [1.3.0] - 2017-11-21
### Added
+2 −2
Original line number Diff line number Diff line
@@ -62,12 +62,12 @@ func MigrationStartupCheck(logger *zap.Logger, db *sql.DB) {
	}
	records, err := migrate.GetMigrationRecords(db, dialect)
	if err != nil {
		logger.Fatal("Could not get migration records", zap.Error(err))
		logger.Fatal("Could not get migration records, run `nakama migrate up`", zap.Error(err))
	}

	diff := len(migrations) - len(records)
	if diff > 0 {
		logger.Warn("DB schema outdated, run `nakama migrate up`", zap.Int("migrations", diff))
		logger.Fatal("DB schema outdated, run `nakama migrate up`", zap.Int("migrations", diff))
	}
	if diff < 0 {
		logger.Warn("DB schema newer, update Nakama", zap.Int64("migrations", int64(math.Abs(float64(diff)))))
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ func main() {
	trackerService.AddDiffListener(presenceNotifier.HandleDiff)
	notificationService := server.NewNotificationService(jsonLogger, db, trackerService, messageRouter, config.GetSocial().Notification)

	runtimePool, err := server.NewRuntimePool(jsonLogger, multiLogger, db, config.GetRuntime(), notificationService)
	runtimePool, err := server.NewRuntimePool(jsonLogger, multiLogger, db, config.GetRuntime(), trackerService, notificationService)
	if err != nil {
		multiLogger.Fatal("Failed initializing runtime modules.", zap.Error(err))
	}
+1 −2
Original line number Diff line number Diff line
@@ -37,8 +37,7 @@ CREATE TABLE IF NOT EXISTS users (
    created_at     BIGINT        CHECK (created_at > 0) NOT NULL,
    updated_at     BIGINT        CHECK (updated_at > 0) NOT NULL,
    verified_at    BIGINT        CHECK (verified_at >= 0) DEFAULT 0 NOT NULL,
    disabled_at    BIGINT        CHECK (disabled_at >= 0) DEFAULT 0 NOT NULL,
    last_online_at BIGINT        CHECK (last_online_at >= 0) DEFAULT 0 NOT NULL
    disabled_at    BIGINT        CHECK (disabled_at >= 0) DEFAULT 0 NOT NULL
);

-- This table should be replaced with an array column in the users table
+1 −5
Original line number Diff line number Diff line
@@ -17,16 +17,12 @@
-- +migrate Up
CREATE TABLE IF NOT EXISTS leaderboard (
    PRIMARY KEY (id),
    FOREIGN KEY (next_id) REFERENCES leaderboard(id),
    FOREIGN KEY (prev_id) REFERENCES leaderboard(id),
    id             BYTEA        NOT NULL,
    authoritative  BOOLEAN      DEFAULT FALSE,
    sort_order     SMALLINT     DEFAULT 1 NOT NULL, -- asc(0), desc(1)
    count          BIGINT       DEFAULT 0 CHECK (count >= 0) NOT NULL,
    reset_schedule VARCHAR(64), -- e.g. cron format: "* * * * * * *"
    metadata       BYTEA        DEFAULT '{}' CHECK (length(metadata) < 16000) NOT NULL,
    next_id        BYTEA        DEFAULT NULL::BYTEA CHECK (next_id <> id),
    prev_id        BYTEA        DEFAULT NULL::BYTEA CHECK (prev_id <> id)
    metadata       BYTEA        DEFAULT '{}' CHECK (length(metadata) < 16000) NOT NULL
);

CREATE TABLE IF NOT EXISTS leaderboard_record (
Loading