Switch startup DB upgrades to EF migrations

This commit is contained in:
2026-02-26 08:49:11 +01:00
parent 0ec19bf682
commit 5763c67f34
9 changed files with 406 additions and 4 deletions

View File

@@ -0,0 +1,78 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using RpgRoller.Data;
using RpgRoller.Domain;
namespace RpgRoller.Migrations;
[DbContext(typeof(RpgRollerDbContext))]
internal sealed class RpgRollerDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "10.0.2");
modelBuilder.Entity<Campaign>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.Name).IsRequired().HasMaxLength(128);
entity.Property(x => x.Ruleset).HasConversion<string>().IsRequired();
entity.Property(x => x.Version).IsRequired();
entity.HasIndex(x => x.GmUserId);
entity.ToTable("Campaigns");
});
modelBuilder.Entity<Character>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.Name).IsRequired().HasMaxLength(128);
entity.HasIndex(x => x.OwnerUserId);
entity.HasIndex(x => x.CampaignId);
entity.ToTable("Characters");
});
modelBuilder.Entity<RollLogEntry>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.Visibility).HasConversion<string>().IsRequired();
entity.Property(x => x.Breakdown).IsRequired().HasMaxLength(256);
entity.Property(x => x.TimestampUtc).IsRequired();
entity.HasIndex(x => x.CampaignId);
entity.HasIndex(x => x.RollerUserId);
entity.HasIndex(x => x.SkillId);
entity.HasIndex(x => x.CharacterId);
entity.ToTable("RollLogEntries");
});
modelBuilder.Entity<Skill>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.Name).IsRequired().HasMaxLength(128);
entity.Property(x => x.DiceRollDefinition).IsRequired().HasMaxLength(128);
entity.Property(x => x.WildDice).IsRequired();
entity.Property(x => x.AllowFumble).IsRequired();
entity.HasIndex(x => x.CharacterId);
entity.ToTable("Skills");
});
modelBuilder.Entity<UserAccount>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.Username).IsRequired().HasMaxLength(64);
entity.Property(x => x.UsernameNormalized).IsRequired().HasMaxLength(64);
entity.Property(x => x.PasswordHash).IsRequired();
entity.Property(x => x.DisplayName).IsRequired().HasMaxLength(128);
entity.HasIndex(x => x.UsernameNormalized).IsUnique();
entity.ToTable("Users");
});
modelBuilder.Entity<UserSession>(entity =>
{
entity.HasKey(x => x.Token);
entity.Property(x => x.Token).HasMaxLength(64);
entity.Property(x => x.CreatedAtUtc).IsRequired();
entity.HasIndex(x => x.UserId);
entity.ToTable("Sessions");
});
}
}