chore: cringed very hard
This commit is contained in:
@@ -11,7 +11,9 @@ namespace LctMonolith.Database.Data;
|
||||
/// </summary>
|
||||
public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
|
||||
{
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) {
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
// Rank related entities
|
||||
public DbSet<Rank> Ranks => Set<Rank>();
|
||||
@@ -92,7 +94,7 @@ public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
|
||||
.WithMany(m => m.ChildMissions)
|
||||
.HasForeignKey(m => m.ParentMissionId)
|
||||
.IsRequired(false);
|
||||
// Dialogue relationship for Mission
|
||||
// Dialogue relationship for Mission (optional dialogue for a mission)
|
||||
b.Entity<Mission>()
|
||||
.HasOne(m => m.Dialogue)
|
||||
.WithOne(d => d.Mission)
|
||||
@@ -171,31 +173,28 @@ public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
|
||||
.WithMany(m => m.PlayerMissions)
|
||||
.HasForeignKey(pm => pm.MissionId);
|
||||
|
||||
// Dialogue configurations
|
||||
// Dialogue configurations (Mission required for Dialogue)
|
||||
b.Entity<Dialogue>()
|
||||
.HasOne(d => d.Mission)
|
||||
.WithOne(m => m.Dialogue)
|
||||
.HasForeignKey<Dialogue>(d => d.MissionId)
|
||||
.IsRequired();
|
||||
|
||||
// DialogueMessage configurations
|
||||
b.Entity<DialogueMessage>()
|
||||
.HasOne(dm => dm.InitialDialogue)
|
||||
// Dialogue -> DialogueMessage relationships (three distinct message slots)
|
||||
b.Entity<Dialogue>()
|
||||
.HasOne(d => d.InitialDialogueMessage)
|
||||
.WithMany()
|
||||
.HasForeignKey(dm => dm.InitialDialogueId)
|
||||
.IsRequired(false)
|
||||
.HasForeignKey(d => d.InitialDialogueMessageId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
b.Entity<DialogueMessage>()
|
||||
.HasOne(dm => dm.InterimDialogue)
|
||||
b.Entity<Dialogue>()
|
||||
.HasOne(d => d.InterimDialogueMessage)
|
||||
.WithMany()
|
||||
.HasForeignKey(dm => dm.InterimDialogueId)
|
||||
.IsRequired(false)
|
||||
.HasForeignKey(d => d.InterimDialogueMessageId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
b.Entity<DialogueMessage>()
|
||||
.HasOne(dm => dm.EndDialogue)
|
||||
b.Entity<Dialogue>()
|
||||
.HasOne(d => d.EndDialogueMessage)
|
||||
.WithMany()
|
||||
.HasForeignKey(dm => dm.EndDialogueId)
|
||||
.IsRequired(false)
|
||||
.HasForeignKey(d => d.EndDialogueMessageId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
// DialogueMessageResponseOption configurations
|
||||
@@ -211,6 +210,18 @@ public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
// UserInventoryItem composite key & relationships
|
||||
b.Entity<UserInventoryItem>()
|
||||
.HasKey(ui => new { ui.UserId, ui.StoreItemId });
|
||||
b.Entity<UserInventoryItem>()
|
||||
.HasOne(ui => ui.User)
|
||||
.WithMany(u => u.Inventory)
|
||||
.HasForeignKey(ui => ui.UserId);
|
||||
b.Entity<UserInventoryItem>()
|
||||
.HasOne(ui => ui.StoreItem)
|
||||
.WithMany(si => si.UserInventory)
|
||||
.HasForeignKey(ui => ui.StoreItemId);
|
||||
|
||||
// Refresh token index unique
|
||||
b.Entity<RefreshToken>().HasIndex(x => x.Token).IsUnique();
|
||||
|
||||
|
||||
@@ -12,36 +12,36 @@ public static class DbSeeder
|
||||
{
|
||||
public static async Task SeedAsync(AppDbContext db, CancellationToken ct = default)
|
||||
{
|
||||
await db.Database.EnsureCreatedAsync(ct);
|
||||
|
||||
if (!await db.Ranks.AnyAsync(ct))
|
||||
{
|
||||
var ranks = new List<Rank>
|
||||
{
|
||||
new() { Title = "Искатель", ExpNeeded = 0 },
|
||||
new() { Title = "Пилот-кандидат", ExpNeeded = 500 },
|
||||
new() { Title = "Принятый в экипаж", ExpNeeded = 1500 }
|
||||
};
|
||||
db.Ranks.AddRange(ranks);
|
||||
Log.Information("Seeded {Count} ranks", ranks.Count);
|
||||
}
|
||||
|
||||
if (!await db.Skills.AnyAsync(ct))
|
||||
{
|
||||
var comps = new[]
|
||||
{
|
||||
"Вера в дело","Стремление к большему","Общение","Аналитика","Командование","Юриспруденция","Трёхмерное мышление","Базовая экономика","Основы аэронавигации"
|
||||
}.Select(n => new Skill { Title = n });
|
||||
db.Skills.AddRange(comps);
|
||||
Log.Information("Seeded competencies");
|
||||
}
|
||||
|
||||
if (!await db.StoreItems.AnyAsync(ct))
|
||||
{
|
||||
db.StoreItems.AddRange(new StoreItem { Name = "Футболка Алабуга", Price = 100 }, new StoreItem { Name = "Брелок Буран", Price = 50 });
|
||||
Log.Information("Seeded store items");
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync(ct);
|
||||
// await db.Database.EnsureCreatedAsync(ct);
|
||||
//
|
||||
// if (!await db.Ranks.AnyAsync(ct))
|
||||
// {
|
||||
// var ranks = new List<Rank>
|
||||
// {
|
||||
// new() { Title = "Искатель", ExpNeeded = 0 },
|
||||
// new() { Title = "Пилот-кандидат", ExpNeeded = 500 },
|
||||
// new() { Title = "Принятый в экипаж", ExpNeeded = 1500 }
|
||||
// };
|
||||
// db.Ranks.AddRange(ranks);
|
||||
// Log.Information("Seeded {Count} ranks", ranks.Count);
|
||||
// }
|
||||
//
|
||||
// if (!await db.Skills.AnyAsync(ct))
|
||||
// {
|
||||
// var comps = new[]
|
||||
// {
|
||||
// "Вера в дело","Стремление к большему","Общение","Аналитика","Командование","Юриспруденция","Трёхмерное мышление","Базовая экономика","Основы аэронавигации"
|
||||
// }.Select(n => new Skill { Title = n });
|
||||
// db.Skills.AddRange(comps);
|
||||
// Log.Information("Seeded competencies");
|
||||
// }
|
||||
//
|
||||
// if (!await db.StoreItems.AnyAsync(ct))
|
||||
// {
|
||||
// db.StoreItems.AddRange(new StoreItem { Name = "Футболка Алабуга", Price = 100 }, new StoreItem { Name = "Брелок Буран", Price = 50 });
|
||||
// Log.Information("Seeded store items");
|
||||
// }
|
||||
//
|
||||
// await db.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user