More migrations, slight db changes
This commit is contained in:
parent
1f7c19b306
commit
56b09ca564
@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl;
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
[DbContext(typeof(NadekoSqliteContext))]
|
||||
[Migration("20161011031532_first")]
|
||||
[Migration("20161011200458_first")]
|
||||
partial class first
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -53,8 +53,6 @@ namespace NadekoBot.Migrations
|
||||
|
||||
b.Property<string>("DMHelpString");
|
||||
|
||||
b.Property<bool>("DontJoinServers");
|
||||
|
||||
b.Property<bool>("ForwardMessages");
|
||||
|
||||
b.Property<bool>("ForwardToAllOwners");
|
||||
@ -440,7 +438,7 @@ namespace NadekoBot.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("BotConfigId");
|
||||
b.Property<int?>("BotConfigId");
|
||||
|
||||
b.Property<string>("ModuleName");
|
||||
|
||||
@ -723,10 +721,9 @@ namespace NadekoBot.Migrations
|
||||
|
||||
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")
|
||||
.HasForeignKey("BotConfigId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.HasForeignKey("BotConfigId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>
|
@ -21,7 +21,6 @@ namespace NadekoBot.Migrations
|
||||
CurrencyPluralName = table.Column<string>(nullable: true),
|
||||
CurrencySign = table.Column<string>(nullable: true),
|
||||
DMHelpString = table.Column<string>(nullable: true),
|
||||
DontJoinServers = table.Column<bool>(nullable: false),
|
||||
ForwardMessages = table.Column<bool>(nullable: false),
|
||||
ForwardToAllOwners = table.Column<bool>(nullable: false),
|
||||
HelpString = table.Column<string>(nullable: true),
|
||||
@ -292,7 +291,7 @@ namespace NadekoBot.Migrations
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("Autoincrement", true),
|
||||
BotConfigId = table.Column<int>(nullable: false),
|
||||
BotConfigId = table.Column<int>(nullable: true),
|
||||
ModuleName = table.Column<string>(nullable: true),
|
||||
Prefix = table.Column<string>(nullable: true)
|
||||
},
|
||||
@ -304,7 +303,7 @@ namespace NadekoBot.Migrations
|
||||
column: x => x.BotConfigId,
|
||||
principalTable: "BotConfig",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
@ -52,8 +52,6 @@ namespace NadekoBot.Migrations
|
||||
|
||||
b.Property<string>("DMHelpString");
|
||||
|
||||
b.Property<bool>("DontJoinServers");
|
||||
|
||||
b.Property<bool>("ForwardMessages");
|
||||
|
||||
b.Property<bool>("ForwardToAllOwners");
|
||||
@ -439,7 +437,7 @@ namespace NadekoBot.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("BotConfigId");
|
||||
b.Property<int?>("BotConfigId");
|
||||
|
||||
b.Property<string>("ModuleName");
|
||||
|
||||
@ -722,10 +720,9 @@ namespace NadekoBot.Migrations
|
||||
|
||||
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")
|
||||
.HasForeignKey("BotConfigId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.HasForeignKey("BotConfigId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>
|
||||
|
@ -15,6 +15,7 @@ using NadekoBot.Modules.Administration.Commands.Migration;
|
||||
using System.Collections.Concurrent;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services.Database;
|
||||
using Microsoft.Data.Sqlite;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
@ -67,9 +68,10 @@ namespace NadekoBot.Modules.Administration
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var botConfig = uow.BotConfig.GetOrCreate();
|
||||
MigrateConfig0_9(botConfig);
|
||||
MigrateConfig0_9(uow, botConfig);
|
||||
MigratePermissions0_9(uow);
|
||||
MigrateServerSpecificConfigs0_9(uow);
|
||||
MigrateDb0_9(uow);
|
||||
|
||||
//NOW save it
|
||||
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)
|
||||
{
|
||||
const string specificConfigsPath = "data/ServerSpecificConfigs.json";
|
||||
@ -119,6 +174,11 @@ namespace NadekoBot.Modules.Administration
|
||||
guildConfig.LogSetting.IsLogging = data.LogChannel != null;
|
||||
guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0;
|
||||
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 =>
|
||||
{
|
||||
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;
|
||||
const string configPath = "data/config.json";
|
||||
@ -255,7 +315,8 @@ namespace NadekoBot.Modules.Administration
|
||||
botConfig.RaceAnimals = races;
|
||||
|
||||
//Prefix
|
||||
var prefix = new HashSet<ModulePrefix>
|
||||
botConfig.ModulePrefixes.Clear();
|
||||
botConfig.ModulePrefixes.AddRange(new HashSet<ModulePrefix>
|
||||
{
|
||||
new ModulePrefix()
|
||||
{
|
||||
@ -299,8 +360,7 @@ namespace NadekoBot.Modules.Administration
|
||||
},
|
||||
new ModulePrefix() {ModuleName = "Pokemon", Prefix = oldConfig.CommandPrefixes.Pokemon},
|
||||
new ModulePrefix() {ModuleName = "Utility", Prefix = oldConfig.CommandPrefixes.Utility}
|
||||
};
|
||||
botConfig.ModulePrefixes = prefix;
|
||||
});
|
||||
|
||||
//Blacklist
|
||||
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
|
||||
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 { }
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Administration.Commands.Migration
|
||||
public bool VoicePlusTextEnabled { get; set; }
|
||||
public bool SendPrivateMessageOnMention { get; set; }
|
||||
public ulong? LogChannel { get; set; } = null;
|
||||
public ulong? LogPresenceChannel = null;
|
||||
public ulong? LogPresenceChannel { get; set; } = null;
|
||||
public HashSet<ulong> LogserverIgnoreChannels { get; set; }
|
||||
public ConcurrentDictionary<ulong, ulong> VoiceChannelLog { get; set; }
|
||||
public HashSet<ulong> ListOfSelfAssignableRoles { get; set; }
|
||||
|
@ -111,9 +111,6 @@ Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY";
|
||||
public string ModuleName { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
|
||||
public int BotConfigId { get; set; } = 1;
|
||||
public BotConfig BotConfig { get; set; }
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ModuleName.GetHashCode();
|
||||
|
Loading…
Reference in New Issue
Block a user