Files
reallife-gamemode/ReallifeGamemode.Database/Models/DatabaseContext.cs
2021-04-19 14:15:08 +02:00

192 lines
6.8 KiB
C#

using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Logging;
/**
* @overview Life of German Reallife - DatabaseContext.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace ReallifeGamemode.Database.Models
{
public partial class DatabaseContext : DbContext
{
public static ILoggerFactory LoggerFactory { get; set; }
private readonly bool useLoggerFactory = false;
public DatabaseContext(bool useLoggerFactory = false)
{
this.useLoggerFactory = useLoggerFactory;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
if (useLoggerFactory && LoggerFactory != null)
{
optionsBuilder.UseLoggerFactory(LoggerFactory);
}
optionsBuilder.EnableSensitiveDataLogging();
optionsBuilder.UseMySql("Host=localhost;Port=3306;Database=gtav-devdb;Username=gtav-dev;Password=Test123");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.UsePropertyAccessMode(PropertyAccessMode.PreferFieldDuringConstruction);
modelBuilder.Entity<Entities.BusinessBankAccount>()
.HasIndex(b => b.BusinessId)
.IsUnique(true);
modelBuilder.Entity<Entities.User>(e =>
{
e.HasIndex(u => u.BusinessId)
.IsUnique(true);
e.HasIndex(u => u.Name)
.IsUnique(true);
});
modelBuilder.Entity<Entities.ServerVehicle>()
.Property(sv => sv.Active)
.HasDefaultValue(true);
modelBuilder.Entity<Entities.VehicleMod>()
.HasIndex(vM => new { vM.ServerVehicleId, vM.Slot }).IsUnique();
}
//User
public DbSet<Entities.Ban> Bans { get; set; }
public DbSet<Entities.Character> Characters { get; set; }
public DbSet<Entities.CharacterCloth> CharacterClothes { get; set; }
public DbSet<Entities.DutyCloth> DutyClothes { get; set; }
public DbSet<Entities.FactionWeapon> FactionWeapons { get; set; }
public DbSet<Entities.ClothCombination> ClothCombinations { get; set; }
public DbSet<Entities.User> Users { get; set; }
public DbSet<Entities.UserVehicle> UserVehicles { get; set; }
public DbSet<Entities.UserBankAccount> UserBankAccounts { get; set; }
public DbSet<Entities.UserWeapon> UserWeapons { get; set; }
//Inventar
public DbSet<Entities.UserItem> UserItems { get; set; }
//Faction
public DbSet<Entities.Faction> Factions { get; set; }
public DbSet<Entities.FactionBankAccount> FactionBankAccounts { get; set; }
public DbSet<Entities.FactionRank> FactionRanks { get; set; }
public DbSet<Entities.FactionVehicle> FactionVehicles { get; set; }
//Shops
public DbSet<Entities.ShopClothe> ShopClothes { get; set; }
public DbSet<Entities.ShopItem> ShopItems { get; set; }
public DbSet<Entities.Weapon> Weapons { get; set; }
public DbSet<Entities.WeaponCategory> WeaponCategories { get; set; }
//Logs
//public DbSet<Logs.Ban> BanLogs { get; set; }
public DbSet<Entities.Logs.BankAccountTransactionHistory> BankAccountTransactionLogs { get; set; }
public DbSet<Entities.Logs.Death> DeathLogs { get; set; }
public DbSet<Entities.Logs.CommandLogEntry> CommandLogs { get; set; }
public DbSet<Entities.Logs.LoginLogoutLogEntry> LoginLogoutLogs { get; set; }
// Chat Logs
public DbSet<Entities.Logs.Chat.ChatLogEntry> ChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.FactionChatLogEntry> FactionChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.DepartmentChatLogEntry> DepartmentChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.GangChatLogEntry> GangChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.GroupChatLogEntry> GroupChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.LeaderChatLogEntry> LeaderChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.LocalChatLogEntry> LocalChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.NewsChatLogEntry> NewsChatLogs { get; set; }
public DbSet<Entities.Logs.Chat.OChatLogEntry> OChatLogs { get; set; }
//Saves
public DbSet<Entities.ATM> ATMs { get; set; }
public DbSet<Entities.Saves.SavedBlip> Blips { get; set; }
public DbSet<Entities.Door> Doors { get; set; }
public DbSet<Entities.GotoPoint> GotoPoints { get; set; }
public DbSet<Entities.Saves.SavedMarker> Markers { get; set; }
public DbSet<Entities.Saves.SavedPed> Peds { get; set; }
public DbSet<Entities.Saves.SavedPickup> Pickups { get; set; }
public DbSet<Entities.Saves.SavedTextLabel> TextLabels { get; set; }
public DbSet<Entities.Saves.SavedVehicle> Vehicles { get; set; }
public DbSet<Entities.ShopVehicle> ShopVehicles { get; set; }
// Business
public DbSet<Entities.BusinessBankAccount> BusinessBankAccounts { get; set; }
public DbSet<Entities.BusinessData> BusinessData { get; set; }
// Control Panel
public DbSet<Entities.News> News { get; set; }
public DbSet<Entities.Location> Locations { get; set; }
// Server Vehicles
public DbSet<Entities.ServerVehicle> ServerVehicles { get; set; }
public DbSet<Entities.VehicleMod> VehicleMods { get; set; }
public DbSet<Entities.VehicleItem> VehicleItems { get; set; }
// Whitelist
public DbSet<Entities.Whitelist> WhitelistEntries { get; set; }
// Interiors
public DbSet<Entities.Interior> Interiors { get; set; }
// Tuning Garages
public DbSet<Entities.TuningGarage> TuningGarages { get; set; }
// Gruppen
public DbSet<Entities.Group> Groups { get; set; }
public DbSet<Entities.GroupBankAccount> GroupBankAccounts { get; set; }
public DbSet<Entities.GroupVehicle> GroupVehicles { get; set; }
// Jobs
public DbSet<Entities.JobVehicle> JobVehicles { get; set; }
// Houses
public DbSet<Entities.House> Houses { get; set; }
public DbSet<Entities.HouseRental> HouseRentals { get; set; }
public DbSet<Entities.HouseBankAccount> HouseBankAccounts { get; set; }
// Bus Routes
public DbSet<Entities.BusRoute> BusRoutes { get; set; }
public DbSet<Entities.BusRoutePoint> BusRoutesPoints { get; set; }
//Driving/Bike/Flight School
public DbSet<Entities.SchoolVehicle> SchoolVehicles { get; set; }
//Noob Vehicles
public DbSet<Entities.NoobVehicle> NoobVehicles { get; set; }
//Noob Spawn Vehicles
public DbSet<Entities.NoobSpawnVehicle> NoobSpawnVehicles { get; set; }
//Gangwar
public DbSet<Entities.Turfs> Turfs { get; set; }
//Server Variablen
public DbSet<Entities.ServerVariable> ServerVariables { get; set; }
}
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<DatabaseContext>
{
public DatabaseContext CreateDbContext(string[] args)
{
return new DatabaseContext();
}
}
}