diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs index 7d824fc6..36b15175 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs @@ -151,6 +151,11 @@ public void DeleteLevel(GameLevel level) #endregion + }); + + //do in separate transaction in a vain attempt to fix Weirdness with favourite level relations having missing levels + this._realm.Write(() => + { this._realm.Remove(level); }); } diff --git a/Refresh.GameServer/Database/GameDatabaseProvider.cs b/Refresh.GameServer/Database/GameDatabaseProvider.cs index 10ceffdf..364f6b11 100644 --- a/Refresh.GameServer/Database/GameDatabaseProvider.cs +++ b/Refresh.GameServer/Database/GameDatabaseProvider.cs @@ -32,7 +32,7 @@ protected GameDatabaseProvider(IDateTimeProvider time) this._time = time; } - protected override ulong SchemaVersion => 100; + protected override ulong SchemaVersion => 101; protected override string Filename => "refreshGameServer.realm"; @@ -165,6 +165,9 @@ protected override void Migrate(Migration migration, ulong oldVersion) // In version 100, we started enforcing lowercase email addresses if (oldVersion < 100) newUser.EmailAddress = oldUser.EmailAddress?.ToLowerInvariant(); + + // Version was bumped here to delete invalid favourite level relations + if (oldVersion < 101) migration.NewRealm.RemoveRange(newUser.FavouriteLevelRelations.Where(r => r.Level == null)); } IQueryable? oldLevels = migration.OldRealm.DynamicApi.All("GameLevel");