using System.Collections.Generic; using Microsoft.EntityFrameworkCore; namespace Content.Server.Database { public class PostgresPreferencesDbContext : PreferencesDbContext { // This is used by the "dotnet ef" CLI tool. public PostgresPreferencesDbContext() { } protected override void OnConfiguring(DbContextOptionsBuilder options) { if(!InitializedWithOptions) options.UseNpgsql("dummy connection string"); } public PostgresPreferencesDbContext(DbContextOptions options) : base(options) { } } public class SqlitePreferencesDbContext : PreferencesDbContext { public SqlitePreferencesDbContext() { } protected override void OnConfiguring(DbContextOptionsBuilder options) { if (!InitializedWithOptions) options.UseSqlite("dummy connection string"); } public SqlitePreferencesDbContext(DbContextOptions options) : base(options) { } } public abstract class PreferencesDbContext : DbContext { /// /// The "dotnet ef" CLI tool uses the parameter-less constructor. /// When that happens we want to supply the via . /// To use the context within the application, the options need to be passed the constructor instead. /// protected readonly bool InitializedWithOptions; public PreferencesDbContext() { } public PreferencesDbContext(DbContextOptions options) : base(options) { InitializedWithOptions = true; } public DbSet Preferences { get; set; } = null!; public DbSet HumanoidProfile { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasIndex(p => p.Username) .IsUnique(); modelBuilder.Entity() .HasIndex(p => new {p.Slot, p.PrefsId}) .IsUnique(); modelBuilder.Entity() .HasIndex(p => new {p.HumanoidProfileId , p.AntagName}) .IsUnique(); } } public class Prefs { public int PrefsId { get; set; } public string Username { get; set; } = null!; public int SelectedCharacterSlot { get; set; } public List HumanoidProfiles { get; } = new List(); } public class HumanoidProfile { public int HumanoidProfileId { get; set; } public int Slot { get; set; } public string SlotName { get; set; } = null!; public string CharacterName { get; set; } = null!; public int Age { get; set; } public string Sex { get; set; } = null!; public string HairName { get; set; } = null!; public string HairColor { get; set; } = null!; public string FacialHairName { get; set; } = null!; public string FacialHairColor { get; set; } = null!; public string EyeColor { get; set; } = null!; public string SkinColor { get; set; } = null!; public List Jobs { get; } = new List(); public List Antags { get; } = new List(); public DbPreferenceUnavailableMode PreferenceUnavailable { get; set; } public int PrefsId { get; set; } public Prefs Prefs { get; set; } = null!; } public class Job { public int JobId { get; set; } public HumanoidProfile Profile { get; set; } = null!; public string JobName { get; set; } = null!; public DbJobPriority Priority { get; set; } } public enum DbJobPriority { // These enum values HAVE to match the ones in JobPriority in Shared. Never = 0, Low = 1, Medium = 2, High = 3 } public class Antag { public int AntagId { get; set; } public HumanoidProfile Profile { get; set; } = null!; public int HumanoidProfileId { get; set; } public string AntagName { get; set; } = null!; } public enum DbPreferenceUnavailableMode { // These enum values HAVE to match the ones in PreferenceUnavailableMode in Shared. StayInLobby = 0, SpawnAsOverflow, } }