diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs index 13f2406a..e74b7925 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs @@ -159,6 +159,7 @@ public void DeleteLevel(GameLevel level) this.UniquePlayLevelRelations.RemoveRange(r => r.Level == level); this.TagLevelRelations.RemoveRange(r => r.Level == level); this.GameReviews.RemoveRange(r => r.Level == level); + this.LevelPlaylistRelations.RemoveRange(r => r.Level == level); IQueryable scores = this.GameSubmittedScores.Where(r => r.Level == level); diff --git a/Refresh.GameServer/Database/GameDatabaseProvider.cs b/Refresh.GameServer/Database/GameDatabaseProvider.cs index 0fdce84b..ecefbe41 100644 --- a/Refresh.GameServer/Database/GameDatabaseProvider.cs +++ b/Refresh.GameServer/Database/GameDatabaseProvider.cs @@ -34,7 +34,7 @@ protected GameDatabaseProvider(IDateTimeProvider time) this._time = time; } - protected override ulong SchemaVersion => 159; + protected override ulong SchemaVersion => 160; protected override string Filename => "refreshGameServer.realm"; @@ -666,28 +666,32 @@ protected override void Migrate(Migration migration, ulong oldVersion) // IQueryable? newGamePlaylists = migration.NewRealm.All(); // if (oldVersion < 155) - // for (int i = 0; i < newGamePlaylists.Count(); i++) - // { - // dynamic oldGamePlaylist = oldGamePlaylists.ElementAt(i); - // GamePlaylist newGamePlaylist = newGamePlaylists.ElementAt(i); - // } + // for (int i = 0; i < newGamePlaylists.Count(); i++) + // { + // dynamic oldGamePlaylist = oldGamePlaylists.ElementAt(i); + // GamePlaylist newGamePlaylist = newGamePlaylists.ElementAt(i); + // } + + // We weren't deleting level playlist relations when a level was deleted. Version 160 fixes this. + if (oldVersion < 160) + migration.NewRealm.RemoveRange(migration.NewRealm.All().Where(r => r.Level == null)); // IQueryable? oldLevelPlaylistRelations = migration.OldRealm.DynamicApi.All("LevelPlaylistRelation"); // IQueryable? newLevelPlaylistRelations = migration.NewRealm.All(); // if (oldVersion < 155) - // for (int i = 0; i < newGamePlaylists.Count(); i++) - // { - // dynamic oldLevelPlaylistRelation = oldLevelPlaylistRelations.ElementAt(i); - // LevelPlaylistRelation newLevelPlaylistRelation = newLevelPlaylistRelations.ElementAt(i); - // } + // for (int i = 0; i < newLevelPlaylistRelations.Count(); i++) + // { + // dynamic oldLevelPlaylistRelation = oldLevelPlaylistRelations.ElementAt(i); + // LevelPlaylistRelation newLevelPlaylistRelation = newLevelPlaylistRelations.ElementAt(i); + // } // IQueryable? oldSubPlaylistRelations = migration.OldRealm.DynamicApi.All("SubPlaylistRelation"); // IQueryable? newSubPlaylistRelations = migration.NewRealm.All(); // if (oldVersion < 155) - // for (int i = 0; i < newGamePlaylists.Count(); i++) - // { - // dynamic oldSubPlaylistRelation = oldSubPlaylistRelations.ElementAt(i); - // SubPlaylistRelation newSubPlaylistRelation = newSubPlaylistRelations.ElementAt(i); - // } + // for (int i = 0; i < newSubPlaylistRelations.Count(); i++) + // { + // dynamic oldSubPlaylistRelation = oldSubPlaylistRelations.ElementAt(i); + // SubPlaylistRelation newSubPlaylistRelation = newSubPlaylistRelations.ElementAt(i); + // } } } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Playlists/LevelPlaylistRelation.cs b/Refresh.GameServer/Types/Playlists/LevelPlaylistRelation.cs index c6efea35..67d42db6 100644 --- a/Refresh.GameServer/Types/Playlists/LevelPlaylistRelation.cs +++ b/Refresh.GameServer/Types/Playlists/LevelPlaylistRelation.cs @@ -3,6 +3,8 @@ namespace Refresh.GameServer.Types.Playlists; +#nullable disable + /// /// A mapping of playlist -> sub-level ///