1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Fix foreign key constraint failure

This commit is contained in:
TocoToucan 2017-10-09 00:30:52 +03:00
parent 5d27c66efa
commit 81b9e08fb6
7 changed files with 17 additions and 21 deletions

View File

@ -19,19 +19,20 @@ namespace osu.Game.Beatmaps
//TODO: should be in database
public int BeatmapVersion;
[NotMapped]
public int? BeatmapOnlineInfoId { get; set; }
[NotMapped]
public int? BeatmapSetOnlineInfoId { get; set; }
public int BeatmapSetInfoId { get; set; }
public BeatmapSetInfo BeatmapSet { get; set; }
public int BeatmapMetadataId { get; set; }
public int? BeatmapMetadataId { get; set; }
public BeatmapMetadata Metadata { get; set; }
//[Required]
public int BeatmapDifficultyId { get; set; }
public BeatmapDifficulty Difficulty { get; set; }

View File

@ -12,6 +12,7 @@ namespace osu.Game.Beatmaps
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[NotMapped]
public int? BeatmapSetOnlineInfoId { get; set; }
public string Title { get; set; }

View File

@ -12,6 +12,7 @@ namespace osu.Game.Beatmaps
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[NotMapped]
public int? BeatmapSetOnlineInfoId { get; set; }
public BeatmapMetadata Metadata { get; set; }

View File

@ -137,22 +137,22 @@ namespace osu.Game.Beatmaps
public BeatmapSetInfo QueryBeatmapSet(Func<BeatmapSetInfo, bool> query)
{
return Connection.BeatmapSetInfo.FirstOrDefault(query);
return Connection.BeatmapSetInfo.Include(b=>b.Beatmaps).Include(b=>b.Metadata).FirstOrDefault(query);
}
public List<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query)
{
return Connection.BeatmapSetInfo.Where(query).ToList();
return Connection.BeatmapSetInfo.Include(b => b.Beatmaps).Include(b => b.Metadata).Include(b=>b.Files).Where(query).ToList();
}
public BeatmapInfo QueryBeatmap(Func<BeatmapInfo, bool> query)
{
return Connection.BeatmapInfo.FirstOrDefault(query);
return Connection.BeatmapInfo.Include(b => b.BeatmapSet).Include(b => b.Metadata).Include(b=>b.Ruleset).FirstOrDefault(query);
}
public List<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query)
{
return Connection.BeatmapInfo.Where(query).ToList();
return Connection.BeatmapInfo.Include(b => b.BeatmapSet).Include(b => b.Metadata).Where(query).ToList();
}
}
}

View File

@ -47,9 +47,6 @@ namespace osu.Game.Database
modelBuilder.Entity<RulesetInfo>().HasIndex(b => b.Name).IsUnique();
modelBuilder.Entity<RulesetInfo>().HasIndex(b => b.InstantiationInfo).IsUnique();
modelBuilder.Entity<RulesetInfo>().HasIndex(b => b.Available);
//modelBuilder.Entity<BeatmapMetadata>().HasOne(b => b.BeatmapSetOnlineInfo).WithOne(bs => bs.BeatmapMetadata).OnDelete(DeleteBehavior.SetNull);
//modelBuilder.Entity<BeatmapSetInfo>().HasOne(b => b.BeatmapSetOnlineInfo).WithOne(bs => bs.BeatmapSetInfo).OnDelete(DeleteBehavior.SetNull);
//modelBuilder.Entity<BeatmapInfo>().HasOne(b => b.BeatmapSetOnlineInfo).WithMany(bs => bs.Beatmaps).OnDelete(DeleteBehavior.SetNull);
}
}
}

View File

@ -83,8 +83,6 @@ namespace osu.Game
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
private OsuDbContext dbContext;
private OsuDbContext createDbContext()
{
var connectionString = Host.Storage.GetDatabaseConnectionString(@"client");
@ -106,7 +104,7 @@ namespace osu.Game
dependencies.Cache(this);
dependencies.Cache(LocalConfig);
dbContext = createDbContext();
using (var dbContext = createDbContext())
if (dbContext.Database.GetPendingMigrations().Any())
dbContext.Database.Migrate();
@ -116,11 +114,11 @@ namespace osu.Game
Token = LocalConfig.Get<string>(OsuSetting.Token)
});
dependencies.Cache(RulesetStore = new RulesetStore(dbContext));
dependencies.Cache(FileStore = new FileStore(dbContext, Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, dbContext, RulesetStore, API, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, dbContext, Host, BeatmapManager, RulesetStore));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(dbContext, RulesetStore));
dependencies.Cache(RulesetStore = new RulesetStore(createDbContext()));
dependencies.Cache(FileStore = new FileStore(createDbContext(), Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, createDbContext(), RulesetStore, API, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, createDbContext(), Host, BeatmapManager, RulesetStore));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(createDbContext(), RulesetStore));
dependencies.Cache(new OsuColour());
//this completely overrides the framework default. will need to change once we make a proper FontStore.
@ -247,8 +245,6 @@ namespace osu.Game
LocalConfig.Save();
}
dbContext?.Dispose();
base.Dispose(isDisposing);
}
}

View File

@ -22,7 +22,7 @@ namespace osu.Game.Screens.Menu
{
private readonly OsuLogo logo;
private const string menu_music_beatmap_hash = "715a09144f885d746644c1983e285044";
private const string menu_music_beatmap_hash = "3c8b1fcc9434dbb29e2fb613d3b9eada9d7bb6c125ceb32396c3b53437280c83";
/// <summary>
/// Whether we have loaded the menu previously.
@ -91,7 +91,6 @@ namespace osu.Game.Screens.Menu
setInfo = beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz")));
setInfo.Protected = true;
beatmaps.Delete(setInfo);
}
}
@ -101,6 +100,7 @@ namespace osu.Game.Screens.Menu
welcome = audio.Sample.Get(@"welcome");
seeya = audio.Sample.Get(@"seeya");
beatmaps.Delete(setInfo);
}
protected override void OnEntering(Screen last)