NadekoBot/src/NadekoBot/Services/Database/NadekoContext.cs

219 lines
8.5 KiB
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using NadekoBot.Services.Database.Models;
2016-10-10 04:38:20 +00:00
using NadekoBot.Extensions;
namespace NadekoBot.Services.Database
{
public abstract class NadekoContext : DbContext
{
2016-08-24 19:38:17 +00:00
public DbSet<Quote> Quotes { get; set; }
public DbSet<Donator> Donators { get; set; }
2016-08-24 23:41:11 +00:00
public DbSet<GuildConfig> GuildConfigs { get; set; }
2016-08-25 17:23:47 +00:00
public DbSet<ClashWar> ClashOfClans { get; set; }
public DbSet<ClashCaller> ClashCallers { get; set; }
2016-08-25 22:05:29 +00:00
public DbSet<Reminder> Reminders { get; set; }
2016-08-26 17:25:54 +00:00
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
public DbSet<BotConfig> BotConfig { get; set; }
2016-08-28 20:59:12 +00:00
public DbSet<Repeater> Repeaters { get; set; }
public DbSet<Currency> Currency { get; set; }
2016-09-04 13:11:02 +00:00
public DbSet<ConvertUnit> ConversionUnits { get; set; }
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
public DbSet<CustomReaction> CustomReactions { get; set; }
//logging
public DbSet<LogSetting> LogSettings { get; set; }
public DbSet<IgnoredLogChannel> IgnoredLogChannels { get; set; }
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
//orphans xD
public DbSet<EightBallResponse> EightBallResponses { get; set; }
public DbSet<RaceAnimal> RaceAnimals { get; set; }
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
public NadekoContext()
{
this.Database.Migrate();
EnsureSeedData();
}
public void EnsureSeedData()
{
if (!BotConfig.Any())
{
var bc = new BotConfig();
2016-10-10 04:38:20 +00:00
bc.ModulePrefixes.AddRange(new HashSet<ModulePrefix>()
{
new ModulePrefix() { ModuleName = "Administration", Prefix = "." },
new ModulePrefix() { ModuleName = "Searches", Prefix = "~" },
new ModulePrefix() { ModuleName = "Translator", Prefix = "~" },
new ModulePrefix() { ModuleName = "NSFW", Prefix = "~" },
new ModulePrefix() { ModuleName = "ClashOfClans", Prefix = "," },
new ModulePrefix() { ModuleName = "Help", Prefix = "-" },
new ModulePrefix() { ModuleName = "Music", Prefix = "!!" },
new ModulePrefix() { ModuleName = "Trello", Prefix = "trello" },
new ModulePrefix() { ModuleName = "Games", Prefix = ">" },
new ModulePrefix() { ModuleName = "Gambling", Prefix = "$" },
new ModulePrefix() { ModuleName = "Permissions", Prefix = ";" },
new ModulePrefix() { ModuleName = "Pokemon", Prefix = ">" },
new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." }
});
2016-10-10 04:38:20 +00:00
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
{
new RaceAnimal { Icon = "🐼", Name = "Panda" },
new RaceAnimal { Icon = "🐻", Name = "Bear" },
new RaceAnimal { Icon = "🐧", Name = "Pengu" },
new RaceAnimal { Icon = "🐨", Name = "Koala" },
new RaceAnimal { Icon = "🐬", Name = "Dolphin" },
new RaceAnimal { Icon = "🐞", Name = "Ladybird" },
new RaceAnimal { Icon = "🦀", Name = "Crab" },
new RaceAnimal { Icon = "🦄", Name = "Unicorn" }
});
2016-10-10 04:38:20 +00:00
bc.EightBallResponses.AddRange(new HashSet<EightBallResponse>
{
new EightBallResponse() { Text = "Most definitely yes" },
new EightBallResponse() { Text = "For sure" },
new EightBallResponse() { Text = "Totally!" },
new EightBallResponse() { Text = "Of course!" },
new EightBallResponse() { Text = "As I see it, yes" },
new EightBallResponse() { Text = "My sources say yes" },
new EightBallResponse() { Text = "Yes" },
new EightBallResponse() { Text = "Most likely" },
new EightBallResponse() { Text = "Perhaps" },
new EightBallResponse() { Text = "Maybe" },
new EightBallResponse() { Text = "Not sure" },
new EightBallResponse() { Text = "It is uncertain" },
new EightBallResponse() { Text = "Ask me again later" },
new EightBallResponse() { Text = "Don't count on it" },
new EightBallResponse() { Text = "Probably not" },
new EightBallResponse() { Text = "Very doubtful" },
new EightBallResponse() { Text = "Most likely no" },
new EightBallResponse() { Text = "Nope" },
new EightBallResponse() { Text = "No" },
new EightBallResponse() { Text = "My sources say no" },
new EightBallResponse() { Text = "Dont even think about it" },
new EightBallResponse() { Text = "Definitely no" },
new EightBallResponse() { Text = "NO - It may cause disease contraction" }
});
BotConfig.Add(bc);
this.SaveChanges();
}
}
2016-08-24 13:29:01 +00:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
#region QUOTES
2016-08-24 17:04:24 +00:00
2016-08-24 13:29:01 +00:00
var quoteEntity = modelBuilder.Entity<Quote>();
2016-08-24 17:04:24 +00:00
#endregion
2016-08-24 17:04:24 +00:00
#region Donators
2016-08-24 13:29:01 +00:00
2016-08-24 17:04:24 +00:00
var donatorEntity = modelBuilder.Entity<Donator>();
donatorEntity
.HasIndex(d => d.UserId)
2016-08-24 13:29:01 +00:00
.IsUnique();
#endregion
#region GuildConfig
2016-08-24 17:04:24 +00:00
2016-08-24 23:41:11 +00:00
var configEntity = modelBuilder.Entity<GuildConfig>();
2016-08-24 17:04:24 +00:00
configEntity
.HasIndex(c => c.GuildId)
.IsUnique();
2016-08-24 13:29:01 +00:00
#endregion
2016-08-25 17:23:47 +00:00
#region BotConfig
var botConfigEntity = modelBuilder.Entity<BotConfig>();
//botConfigEntity
// .HasMany(c => c.ModulePrefixes)
// .WithOne(mp => mp.BotConfig)
// .HasForeignKey(mp => mp.BotConfigId);
#endregion
2016-08-25 17:23:47 +00:00
#region ClashOfClans
var callersEntity = modelBuilder.Entity<ClashCaller>();
callersEntity
.HasOne(c => c.ClashWar)
.WithMany(c => c.Bases);
#endregion
2016-08-26 17:25:54 +00:00
#region Self Assignable Roles
var selfassignableRolesEntity = modelBuilder.Entity<SelfAssignedRole>();
selfassignableRolesEntity
.HasIndex(s => new { s.GuildId, s.RoleId })
.IsUnique();
#endregion
2016-08-28 20:59:12 +00:00
#region Repeater
var repeaterEntity = modelBuilder.Entity<Repeater>();
repeaterEntity
.HasIndex(r => r.ChannelId)
.IsUnique();
#endregion
#region Currency
var currencyEntity = modelBuilder.Entity<Currency>();
currencyEntity
.HasIndex(c => c.UserId)
.IsUnique();
#endregion
#region Permission
var permissionEntity = modelBuilder.Entity<Permission>();
permissionEntity
.HasOne(p => p.Next)
.WithOne(p => p.Previous)
.IsRequired(false);
#endregion
#region LogSettings
//var logSettingEntity = modelBuilder.Entity<LogSetting>();
//logSettingEntity
// .HasMany(ls => ls.IgnoredChannels)
// .WithOne(ls => ls.LogSetting)
// .HasPrincipalKey(ls => ls.id;
//logSettingEntity
// .HasMany(ls => ls.IgnoredVoicePresenceChannelIds)
// .WithOne(ls => ls.LogSetting);
#endregion
2016-10-02 01:00:03 +00:00
#region MusicPlaylists
var musicPlaylistEntity = modelBuilder.Entity<MusicPlaylist>();
musicPlaylistEntity
2016-10-02 02:15:57 +00:00
.HasMany(p => p.Songs)
2016-10-02 01:00:03 +00:00
.WithOne()
.OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Cascade);
#endregion
2016-08-24 13:29:01 +00:00
}
2016-08-24 22:39:02 +00:00
protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder);
}
}