More migrations, slight db changes

This commit is contained in:
Kwoth 2016-10-11 22:06:31 +02:00
parent 1f7c19b306
commit 56b09ca564
6 changed files with 130 additions and 67 deletions

View File

@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl;
namespace NadekoBot.Migrations namespace NadekoBot.Migrations
{ {
[DbContext(typeof(NadekoSqliteContext))] [DbContext(typeof(NadekoSqliteContext))]
[Migration("20161011031532_first")] [Migration("20161011200458_first")]
partial class first partial class first
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -53,8 +53,6 @@ namespace NadekoBot.Migrations
b.Property<string>("DMHelpString"); b.Property<string>("DMHelpString");
b.Property<bool>("DontJoinServers");
b.Property<bool>("ForwardMessages"); b.Property<bool>("ForwardMessages");
b.Property<bool>("ForwardToAllOwners"); b.Property<bool>("ForwardToAllOwners");
@ -440,7 +438,7 @@ namespace NadekoBot.Migrations
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
b.Property<int>("BotConfigId"); b.Property<int?>("BotConfigId");
b.Property<string>("ModuleName"); b.Property<string>("ModuleName");
@ -723,10 +721,9 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig") b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
.WithMany("ModulePrefixes") .WithMany("ModulePrefixes")
.HasForeignKey("BotConfigId") .HasForeignKey("BotConfigId");
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>

View File

@ -21,7 +21,6 @@ namespace NadekoBot.Migrations
CurrencyPluralName = table.Column<string>(nullable: true), CurrencyPluralName = table.Column<string>(nullable: true),
CurrencySign = table.Column<string>(nullable: true), CurrencySign = table.Column<string>(nullable: true),
DMHelpString = table.Column<string>(nullable: true), DMHelpString = table.Column<string>(nullable: true),
DontJoinServers = table.Column<bool>(nullable: false),
ForwardMessages = table.Column<bool>(nullable: false), ForwardMessages = table.Column<bool>(nullable: false),
ForwardToAllOwners = table.Column<bool>(nullable: false), ForwardToAllOwners = table.Column<bool>(nullable: false),
HelpString = table.Column<string>(nullable: true), HelpString = table.Column<string>(nullable: true),
@ -292,7 +291,7 @@ namespace NadekoBot.Migrations
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true), .Annotation("Autoincrement", true),
BotConfigId = table.Column<int>(nullable: false), BotConfigId = table.Column<int>(nullable: true),
ModuleName = table.Column<string>(nullable: true), ModuleName = table.Column<string>(nullable: true),
Prefix = table.Column<string>(nullable: true) Prefix = table.Column<string>(nullable: true)
}, },
@ -304,7 +303,7 @@ namespace NadekoBot.Migrations
column: x => x.BotConfigId, column: x => x.BotConfigId,
principalTable: "BotConfig", principalTable: "BotConfig",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(

View File

@ -52,8 +52,6 @@ namespace NadekoBot.Migrations
b.Property<string>("DMHelpString"); b.Property<string>("DMHelpString");
b.Property<bool>("DontJoinServers");
b.Property<bool>("ForwardMessages"); b.Property<bool>("ForwardMessages");
b.Property<bool>("ForwardToAllOwners"); b.Property<bool>("ForwardToAllOwners");
@ -439,7 +437,7 @@ namespace NadekoBot.Migrations
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
b.Property<int>("BotConfigId"); b.Property<int?>("BotConfigId");
b.Property<string>("ModuleName"); b.Property<string>("ModuleName");
@ -722,10 +720,9 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig") b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
.WithMany("ModulePrefixes") .WithMany("ModulePrefixes")
.HasForeignKey("BotConfigId") .HasForeignKey("BotConfigId");
.OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>

View File

@ -15,6 +15,7 @@ using NadekoBot.Modules.Administration.Commands.Migration;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Services.Database; using NadekoBot.Services.Database;
using Microsoft.Data.Sqlite;
namespace NadekoBot.Modules.Administration namespace NadekoBot.Modules.Administration
{ {
@ -67,9 +68,10 @@ namespace NadekoBot.Modules.Administration
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var botConfig = uow.BotConfig.GetOrCreate(); var botConfig = uow.BotConfig.GetOrCreate();
MigrateConfig0_9(botConfig); MigrateConfig0_9(uow, botConfig);
MigratePermissions0_9(uow); MigratePermissions0_9(uow);
MigrateServerSpecificConfigs0_9(uow); MigrateServerSpecificConfigs0_9(uow);
MigrateDb0_9(uow);
//NOW save it //NOW save it
botConfig.MigrationVersion = 1; botConfig.MigrationVersion = 1;
@ -77,6 +79,59 @@ namespace NadekoBot.Modules.Administration
} }
} }
private void MigrateDb0_9(IUnitOfWork uow)
{
var db = new SqliteConnection("Data Source=data/nadekobot.sqlite;Version=3;");
db.Open();
var com = db.CreateCommand();
com.CommandText = "SELECT * FROM Announcement";
var reader = com.ExecuteReader();
while(reader.Read())
{
var gid = (ulong)reader["ServerId"];
var greet = (bool)reader["Greet"];
var greetDM = (bool)reader["GreetPM"];
var greetChannel = (ulong)reader["GreetChannelId"];
var greetMsg = (string)reader["GreetText"];
var bye = (bool)reader["Bye"];
var byeDM = (bool)reader["ByePM"];
var byeChannel = (ulong)reader["ByeChannelId"];
var byeMsg = (string)reader["ByeText"];
bool grdel = (bool)reader["DeleteGreetMessages"];
var byedel = grdel;
var gc = uow.GuildConfigs.For(gid);
if (greetDM)
gc.SendDmGreetMessage = greet;
else
gc.SendChannelGreetMessage = greet;
gc.GreetMessageChannelId = greetChannel;
gc.ChannelGreetMessageText = greetMsg;
gc.SendChannelByeMessage = bye;
gc.ByeMessageChannelId = byeChannel;
gc.ChannelByeMessageText = byeMsg;
gc.AutoDeleteByeMessages = gc.AutoDeleteGreetMessages = grdel;
}
var com2 = db.CreateCommand();
com.CommandText = "SELECT * FROM Announcement";
var reader2 = com.ExecuteReader();
while (reader2.Read())
{
uow.Currency.Add(new Currency()
{
Amount = (long)reader2["Value"],
UserId = (ulong)reader2["UserId"]
});
}
db.Close();
}
private void MigrateServerSpecificConfigs0_9(IUnitOfWork uow) private void MigrateServerSpecificConfigs0_9(IUnitOfWork uow)
{ {
const string specificConfigsPath = "data/ServerSpecificConfigs.json"; const string specificConfigsPath = "data/ServerSpecificConfigs.json";
@ -119,6 +174,11 @@ namespace NadekoBot.Modules.Administration
guildConfig.LogSetting.IsLogging = data.LogChannel != null; guildConfig.LogSetting.IsLogging = data.LogChannel != null;
guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0; guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0;
guildConfig.LogSetting.IgnoredChannels = new HashSet<IgnoredLogChannel>(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id })); guildConfig.LogSetting.IgnoredChannels = new HashSet<IgnoredLogChannel>(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id }));
guildConfig.LogSetting.LogUserPresence = data.LogPresenceChannel != null;
guildConfig.LogSetting.UserPresenceChannelId = data.LogPresenceChannel ?? 0;
guildConfig.FollowedStreams = new HashSet<FollowedStream>(data.ObservingStreams.Select(x => guildConfig.FollowedStreams = new HashSet<FollowedStream>(data.ObservingStreams.Select(x =>
{ {
FollowedStream.FollowedStreamType type = FollowedStream.FollowedStreamType.Twitch; FollowedStream.FollowedStreamType type = FollowedStream.FollowedStreamType.Twitch;
@ -212,7 +272,7 @@ namespace NadekoBot.Modules.Administration
} }
private void MigrateConfig0_9(BotConfig botConfig) private void MigrateConfig0_9(IUnitOfWork uow, BotConfig botConfig)
{ {
Config0_9 oldConfig; Config0_9 oldConfig;
const string configPath = "data/config.json"; const string configPath = "data/config.json";
@ -255,52 +315,52 @@ namespace NadekoBot.Modules.Administration
botConfig.RaceAnimals = races; botConfig.RaceAnimals = races;
//Prefix //Prefix
var prefix = new HashSet<ModulePrefix> botConfig.ModulePrefixes.Clear();
botConfig.ModulePrefixes.AddRange(new HashSet<ModulePrefix>
{
new ModulePrefix()
{ {
new ModulePrefix() ModuleName = "Administration",
{ Prefix = oldConfig.CommandPrefixes.Administration
ModuleName = "Administration", },
Prefix = oldConfig.CommandPrefixes.Administration new ModulePrefix()
}, {
new ModulePrefix() ModuleName = "Searches",
{ Prefix = oldConfig.CommandPrefixes.Searches
ModuleName = "Searches", },
Prefix = oldConfig.CommandPrefixes.Searches new ModulePrefix() {ModuleName = "NSFW", Prefix = oldConfig.CommandPrefixes.NSFW},
}, new ModulePrefix()
new ModulePrefix() {ModuleName = "NSFW", Prefix = oldConfig.CommandPrefixes.NSFW}, {
new ModulePrefix() ModuleName = "Conversations",
{ Prefix = oldConfig.CommandPrefixes.Conversations
ModuleName = "Conversations", },
Prefix = oldConfig.CommandPrefixes.Conversations new ModulePrefix()
}, {
new ModulePrefix() ModuleName = "ClashOfClans",
{ Prefix = oldConfig.CommandPrefixes.ClashOfClans
ModuleName = "ClashOfClans", },
Prefix = oldConfig.CommandPrefixes.ClashOfClans new ModulePrefix() {ModuleName = "Help", Prefix = oldConfig.CommandPrefixes.Help},
}, new ModulePrefix() {ModuleName = "Music", Prefix = oldConfig.CommandPrefixes.Music},
new ModulePrefix() {ModuleName = "Help", Prefix = oldConfig.CommandPrefixes.Help}, new ModulePrefix() {ModuleName = "Trello", Prefix = oldConfig.CommandPrefixes.Trello},
new ModulePrefix() {ModuleName = "Music", Prefix = oldConfig.CommandPrefixes.Music}, new ModulePrefix() {ModuleName = "Games", Prefix = oldConfig.CommandPrefixes.Games},
new ModulePrefix() {ModuleName = "Trello", Prefix = oldConfig.CommandPrefixes.Trello}, new ModulePrefix()
new ModulePrefix() {ModuleName = "Games", Prefix = oldConfig.CommandPrefixes.Games}, {
new ModulePrefix() ModuleName = "Gambling",
{ Prefix = oldConfig.CommandPrefixes.Gambling
ModuleName = "Gambling", },
Prefix = oldConfig.CommandPrefixes.Gambling new ModulePrefix()
}, {
new ModulePrefix() ModuleName = "Permissions",
{ Prefix = oldConfig.CommandPrefixes.Permissions
ModuleName = "Permissions", },
Prefix = oldConfig.CommandPrefixes.Permissions new ModulePrefix()
}, {
new ModulePrefix() ModuleName = "Programming",
{ Prefix = oldConfig.CommandPrefixes.Programming
ModuleName = "Programming", },
Prefix = oldConfig.CommandPrefixes.Programming new ModulePrefix() {ModuleName = "Pokemon", Prefix = oldConfig.CommandPrefixes.Pokemon},
}, new ModulePrefix() {ModuleName = "Utility", Prefix = oldConfig.CommandPrefixes.Utility}
new ModulePrefix() {ModuleName = "Pokemon", Prefix = oldConfig.CommandPrefixes.Pokemon}, });
new ModulePrefix() {ModuleName = "Utility", Prefix = oldConfig.CommandPrefixes.Utility}
};
botConfig.ModulePrefixes = prefix;
//Blacklist //Blacklist
var blacklist = new HashSet<BlacklistItem>(oldConfig.ServerBlacklist.Select(server => new BlacklistItem() { ItemId = server, Type = BlacklistItem.BlacklistType.Server })); var blacklist = new HashSet<BlacklistItem>(oldConfig.ServerBlacklist.Select(server => new BlacklistItem() { ItemId = server, Type = BlacklistItem.BlacklistType.Server }));
@ -311,6 +371,19 @@ namespace NadekoBot.Modules.Administration
//Eightball //Eightball
botConfig.EightBallResponses = new HashSet<EightBallResponse>(oldConfig._8BallResponses.Select(response => new EightBallResponse() { Text = response })); botConfig.EightBallResponses = new HashSet<EightBallResponse>(oldConfig._8BallResponses.Select(response => new EightBallResponse() { Text = response }));
//customreactions
uow.CustomReactions.AddRange(oldConfig.CustomReactions.SelectMany(cr =>
{
return cr.Value.Select(res => new CustomReaction()
{
GuildId = 0,
IsRegex = false,
OwnerOnly = false,
Response = res,
Trigger = cr.Key,
});
}).ToArray());
try { File.Move(configPath, "./data/DELETE_ME_config.json"); } catch { } try { File.Move(configPath, "./data/DELETE_ME_config.json"); } catch { }
} }
} }

View File

@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Administration.Commands.Migration
public bool VoicePlusTextEnabled { get; set; } public bool VoicePlusTextEnabled { get; set; }
public bool SendPrivateMessageOnMention { get; set; } public bool SendPrivateMessageOnMention { get; set; }
public ulong? LogChannel { get; set; } = null; public ulong? LogChannel { get; set; } = null;
public ulong? LogPresenceChannel = null; public ulong? LogPresenceChannel { get; set; } = null;
public HashSet<ulong> LogserverIgnoreChannels { get; set; } public HashSet<ulong> LogserverIgnoreChannels { get; set; }
public ConcurrentDictionary<ulong, ulong> VoiceChannelLog { get; set; } public ConcurrentDictionary<ulong, ulong> VoiceChannelLog { get; set; }
public HashSet<ulong> ListOfSelfAssignableRoles { get; set; } public HashSet<ulong> ListOfSelfAssignableRoles { get; set; }

View File

@ -111,9 +111,6 @@ Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY";
public string ModuleName { get; set; } public string ModuleName { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }
public int BotConfigId { get; set; } = 1;
public BotConfig BotConfig { get; set; }
public override int GetHashCode() public override int GetHashCode()
{ {
return ModuleName.GetHashCode(); return ModuleName.GetHashCode();