2016-08-24 01:32:48 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2016-10-10 04:38:20 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
2016-08-24 01:32:48 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Services.Database
|
|
|
|
|
{
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
public class NadekoContextFactory : IDbContextFactory<NadekoContext>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// :\ Used for migrations
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="options"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public NadekoContext Create(DbContextFactoryOptions options)
|
|
|
|
|
{
|
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder();
|
2017-06-21 22:22:50 +00:00
|
|
|
|
optionsBuilder.UseSqlite("Filename=./data/NadekoBot.db");
|
2017-06-21 22:12:29 +00:00
|
|
|
|
var ctx = new NadekoContext(optionsBuilder.Options);
|
2017-06-21 22:22:50 +00:00
|
|
|
|
ctx.Database.SetCommandTimeout(60);
|
2017-06-21 22:12:29 +00:00
|
|
|
|
return ctx;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 11:01:02 +00:00
|
|
|
|
public class NadekoContext : DbContext
|
2016-08-24 01:32:48 +00:00
|
|
|
|
{
|
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; }
|
2016-08-28 00:46:36 +00:00
|
|
|
|
public DbSet<BotConfig> BotConfig { get; set; }
|
2016-08-30 01:17:16 +00:00
|
|
|
|
public DbSet<Currency> Currency { get; set; }
|
2016-09-04 13:11:02 +00:00
|
|
|
|
public DbSet<ConvertUnit> ConversionUnits { get; set; }
|
2016-10-01 03:49:05 +00:00
|
|
|
|
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
|
2016-10-08 02:25:12 +00:00
|
|
|
|
public DbSet<CustomReaction> CustomReactions { get; set; }
|
2016-10-15 00:58:15 +00:00
|
|
|
|
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }
|
2016-11-27 02:51:10 +00:00
|
|
|
|
public DbSet<UserPokeTypes> PokeGame { get; set; }
|
2017-01-22 20:06:10 +00:00
|
|
|
|
public DbSet<WaifuUpdate> WaifuUpdates { get; set; }
|
2017-03-30 01:51:54 +00:00
|
|
|
|
public DbSet<Warning> Warnings { get; set; }
|
2016-08-24 01:32:48 +00:00
|
|
|
|
|
2016-09-05 10:27:58 +00:00
|
|
|
|
//logging
|
|
|
|
|
public DbSet<LogSetting> LogSettings { get; set; }
|
|
|
|
|
public DbSet<IgnoredLogChannel> IgnoredLogChannels { get; set; }
|
|
|
|
|
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
|
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
//orphans xD
|
|
|
|
|
public DbSet<EightBallResponse> EightBallResponses { get; set; }
|
|
|
|
|
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
|
|
|
|
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
2017-04-01 22:01:02 +00:00
|
|
|
|
public DbSet<RewardedUser> RewardedUsers { get; set; }
|
2016-09-10 19:40:25 +00:00
|
|
|
|
|
2017-01-22 20:06:10 +00:00
|
|
|
|
public NadekoContext() : base()
|
2016-09-14 01:38:44 +00:00
|
|
|
|
{
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
2016-11-15 11:01:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NadekoContext(DbContextOptions options) : base(options)
|
|
|
|
|
{
|
2016-09-14 01:38:44 +00:00
|
|
|
|
}
|
2017-01-10 12:37:35 +00:00
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
public void EnsureSeedData()
|
|
|
|
|
{
|
|
|
|
|
if (!BotConfig.Any())
|
|
|
|
|
{
|
|
|
|
|
var bc = new BotConfig();
|
|
|
|
|
|
2016-10-10 04:38:20 +00:00
|
|
|
|
bc.ModulePrefixes.AddRange(new HashSet<ModulePrefix>()
|
2016-09-10 19:40:25 +00:00
|
|
|
|
{
|
|
|
|
|
new ModulePrefix() { ModuleName = "Administration", Prefix = "." },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Searches", Prefix = "~" },
|
2016-09-10 19:45:12 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "Translator", Prefix = "~" },
|
2016-09-10 19:40:25 +00:00
|
|
|
|
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 = ">" },
|
2016-10-08 02:25:12 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
|
2016-11-27 02:51:10 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." },
|
|
|
|
|
new ModulePrefix() { ModuleName = "PokeGame", Prefix = ">" }
|
2016-09-10 19:40:25 +00:00
|
|
|
|
});
|
2016-10-10 04:38:20 +00:00
|
|
|
|
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
|
2016-09-10 19:40:25 +00:00
|
|
|
|
{
|
|
|
|
|
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>
|
2016-09-10 19:40:25 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2017-02-14 13:30:21 +00:00
|
|
|
|
//var quoteEntity = modelBuilder.Entity<Quote>();
|
2016-08-24 13:29:01 +00:00
|
|
|
|
|
2016-08-24 17:04:24 +00:00
|
|
|
|
#endregion
|
2016-08-28 00:46:36 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
#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();
|
|
|
|
|
|
2017-01-10 19:37:41 +00:00
|
|
|
|
modelBuilder.Entity<AntiSpamSetting>()
|
|
|
|
|
.HasOne(x => x.GuildConfig)
|
|
|
|
|
.WithOne(x => x.AntiSpamSetting);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<AntiRaidSetting>()
|
|
|
|
|
.HasOne(x => x.GuildConfig)
|
|
|
|
|
.WithOne(x => x.AntiRaidSetting);
|
|
|
|
|
|
|
|
|
|
//modelBuilder.Entity<ProtectionIgnoredChannel>()
|
|
|
|
|
// .HasAlternateKey(c => new { c.ChannelId, c.ProtectionType });
|
|
|
|
|
|
2016-08-24 13:29:01 +00:00
|
|
|
|
#endregion
|
2016-08-25 17:23:47 +00:00
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
#region BotConfig
|
2017-02-14 13:30:21 +00:00
|
|
|
|
//var botConfigEntity = modelBuilder.Entity<BotConfig>();
|
2016-09-10 19:40:25 +00:00
|
|
|
|
//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
|
|
|
|
|
2016-08-30 01:17:16 +00:00
|
|
|
|
#region Currency
|
|
|
|
|
var currencyEntity = modelBuilder.Entity<Currency>();
|
|
|
|
|
|
|
|
|
|
currencyEntity
|
|
|
|
|
.HasIndex(c => c.UserId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
#endregion
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-09-27 13:26:37 +00:00
|
|
|
|
#region Permission
|
|
|
|
|
var permissionEntity = modelBuilder.Entity<Permission>();
|
|
|
|
|
permissionEntity
|
|
|
|
|
.HasOne(p => p.Next)
|
2016-10-07 13:00:42 +00:00
|
|
|
|
.WithOne(p => p.Previous)
|
|
|
|
|
.IsRequired(false);
|
2016-09-27 13:26:37 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2016-09-05 10:27:58 +00:00
|
|
|
|
#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);
|
2016-11-27 02:51:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region PokeGame
|
|
|
|
|
var pokeGameEntity = modelBuilder.Entity<UserPokeTypes>();
|
|
|
|
|
|
|
|
|
|
pokeGameEntity
|
|
|
|
|
.HasIndex(pt => pt.UserId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
|
2016-10-02 01:00:03 +00:00
|
|
|
|
|
2017-01-10 19:37:41 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2017-01-12 19:19:56 +00:00
|
|
|
|
#region CommandPrice
|
2017-01-14 16:37:11 +00:00
|
|
|
|
//well, i failed
|
2017-01-12 19:19:56 +00:00
|
|
|
|
modelBuilder.Entity<CommandPrice>()
|
|
|
|
|
.HasIndex(cp => cp.Price)
|
|
|
|
|
.IsUnique();
|
2017-01-14 16:37:11 +00:00
|
|
|
|
|
|
|
|
|
//modelBuilder.Entity<CommandCost>()
|
|
|
|
|
// .HasIndex(cp => cp.CommandName)
|
|
|
|
|
// .IsUnique();
|
2016-10-02 01:00:03 +00:00
|
|
|
|
#endregion
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
#region Waifus
|
|
|
|
|
|
|
|
|
|
var wi = modelBuilder.Entity<WaifuInfo>();
|
|
|
|
|
wi.HasOne(x => x.Waifu)
|
|
|
|
|
.WithOne();
|
|
|
|
|
// //.HasForeignKey<WaifuInfo>(w => w.WaifuId)
|
|
|
|
|
// //.IsRequired(true);
|
|
|
|
|
|
|
|
|
|
//wi.HasOne(x => x.Claimer)
|
|
|
|
|
// .WithOne();
|
|
|
|
|
// //.HasForeignKey<WaifuInfo>(w => w.ClaimerId)
|
|
|
|
|
// //.IsRequired(false);
|
|
|
|
|
|
|
|
|
|
var du = modelBuilder.Entity<DiscordUser>();
|
|
|
|
|
du.HasAlternateKey(w => w.UserId);
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-03-30 01:51:54 +00:00
|
|
|
|
|
|
|
|
|
#region Warnings
|
|
|
|
|
var warn = modelBuilder.Entity<Warning>();
|
|
|
|
|
#endregion
|
2017-04-01 22:01:02 +00:00
|
|
|
|
|
|
|
|
|
#region PatreonRewards
|
|
|
|
|
var pr = modelBuilder.Entity<RewardedUser>();
|
|
|
|
|
pr.HasIndex(x => x.UserId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
#endregion
|
2016-08-24 13:29:01 +00:00
|
|
|
|
}
|
2016-08-24 01:32:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|