From 453ac3efd282b697fbdcea91d42f285d99721d05 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 21 Sep 2021 22:48:18 +0200 Subject: [PATCH] Re-did migration as the old one was wrong --- src/NadekoBot/Db/Models/IgnoredLogItem.cs | 1 + src/NadekoBot/Db/NadekoContext.cs | 2 +- ...204645_logignore-user-channel.Designer.cs} | 17 ++++----- ... 20210921204645_logignore-user-channel.cs} | 37 +++++++++++++++++-- .../Migrations/NadekoContextModelSnapshot.cs | 13 +++---- 5 files changed, 47 insertions(+), 23 deletions(-) rename src/NadekoBot/Migrations/{20210921194708_logignore-user-role-channel.Designer.cs => 20210921204645_logignore-user-channel.Designer.cs} (99%) rename src/NadekoBot/Migrations/{20210921194708_logignore-user-role-channel.cs => 20210921204645_logignore-user-channel.cs} (61%) diff --git a/src/NadekoBot/Db/Models/IgnoredLogItem.cs b/src/NadekoBot/Db/Models/IgnoredLogItem.cs index 753449884..598e7c316 100644 --- a/src/NadekoBot/Db/Models/IgnoredLogItem.cs +++ b/src/NadekoBot/Db/Models/IgnoredLogItem.cs @@ -2,6 +2,7 @@ { public class IgnoredLogItem : DbEntity { + public int LogSettingId { get; set; } public LogSetting LogSetting { get; set; } public ulong LogItemId { get; set; } public IgnoredItemType ItemType { get; set; } diff --git a/src/NadekoBot/Db/NadekoContext.cs b/src/NadekoBot/Db/NadekoContext.cs index d715a77f2..bb223b9df 100644 --- a/src/NadekoBot/Db/NadekoContext.cs +++ b/src/NadekoBot/Db/NadekoContext.cs @@ -349,7 +349,7 @@ namespace NadekoBot.Services.Database .OnDelete(DeleteBehavior.Cascade)); modelBuilder.Entity(ili => ili - .HasIndex(x => new { ItemId = x.LogItemId, x.ItemType }) + .HasIndex(x => new { x.LogSettingId, x.LogItemId, x.ItemType }) .IsUnique()); #endregion diff --git a/src/NadekoBot/Migrations/20210921194708_logignore-user-role-channel.Designer.cs b/src/NadekoBot/Migrations/20210921204645_logignore-user-channel.Designer.cs similarity index 99% rename from src/NadekoBot/Migrations/20210921194708_logignore-user-role-channel.Designer.cs rename to src/NadekoBot/Migrations/20210921204645_logignore-user-channel.Designer.cs index c85d5c1dd..6a8f237e4 100644 --- a/src/NadekoBot/Migrations/20210921194708_logignore-user-role-channel.Designer.cs +++ b/src/NadekoBot/Migrations/20210921204645_logignore-user-channel.Designer.cs @@ -9,8 +9,8 @@ using NadekoBot.Services.Database; namespace NadekoBot.Migrations { [DbContext(typeof(NadekoContext))] - [Migration("20210921194708_logignore-user-role-channel")] - partial class logignoreuserrolechannel + [Migration("20210921204645_logignore-user-channel")] + partial class logignoreuserchannel { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -864,14 +864,12 @@ namespace NadekoBot.Migrations b.Property("LogItemId") .HasColumnType("INTEGER"); - b.Property("LogSettingId") + b.Property("LogSettingId") .HasColumnType("INTEGER"); b.HasKey("Id"); - b.HasIndex("LogSettingId"); - - b.HasIndex("LogItemId", "ItemType") + b.HasIndex("LogSettingId", "LogItemId", "ItemType") .IsUnique(); b.ToTable("IgnoredLogChannels"); @@ -2282,7 +2280,8 @@ namespace NadekoBot.Migrations b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") .WithMany("LogIgnores") .HasForeignKey("LogSettingId") - .OnDelete(DeleteBehavior.Cascade); + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("LogSetting"); }); @@ -2290,7 +2289,7 @@ namespace NadekoBot.Migrations modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => { b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") - .WithMany("IgnoredVoicePresenceChannelIds") + .WithMany() .HasForeignKey("LogSettingId"); b.Navigation("LogSetting"); @@ -2607,8 +2606,6 @@ namespace NadekoBot.Migrations modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b => { - b.Navigation("IgnoredVoicePresenceChannelIds"); - b.Navigation("LogIgnores"); }); diff --git a/src/NadekoBot/Migrations/20210921194708_logignore-user-role-channel.cs b/src/NadekoBot/Migrations/20210921204645_logignore-user-channel.cs similarity index 61% rename from src/NadekoBot/Migrations/20210921194708_logignore-user-role-channel.cs rename to src/NadekoBot/Migrations/20210921204645_logignore-user-channel.cs index b2badfca9..ead152428 100644 --- a/src/NadekoBot/Migrations/20210921194708_logignore-user-role-channel.cs +++ b/src/NadekoBot/Migrations/20210921204645_logignore-user-channel.cs @@ -2,19 +2,35 @@ namespace NadekoBot.Migrations { - public partial class logignoreuserrolechannel : Migration + public partial class logignoreuserchannel : Migration { protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.Sql("DELETE FROM IgnoredLogChannels WHERE LogSettingId is NULL"); + migrationBuilder.DropForeignKey( name: "FK_IgnoredLogChannels_LogSettings_LogSettingId", table: "IgnoredLogChannels"); + migrationBuilder.DropIndex( + name: "IX_IgnoredLogChannels_LogSettingId", + table: "IgnoredLogChannels"); + migrationBuilder.RenameColumn( name: "ChannelId", table: "IgnoredLogChannels", newName: "LogItemId"); + migrationBuilder.AlterColumn( + name: "LogSettingId", + table: "IgnoredLogChannels", + type: "INTEGER", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + migrationBuilder.AddColumn( name: "ItemType", table: "IgnoredLogChannels", @@ -23,9 +39,9 @@ namespace NadekoBot.Migrations defaultValue: 0); migrationBuilder.CreateIndex( - name: "IX_IgnoredLogChannels_LogItemId_ItemType", + name: "IX_IgnoredLogChannels_LogSettingId_LogItemId_ItemType", table: "IgnoredLogChannels", - columns: new[] { "LogItemId", "ItemType" }, + columns: new[] { "LogSettingId", "LogItemId", "ItemType" }, unique: true); migrationBuilder.AddForeignKey( @@ -44,7 +60,7 @@ namespace NadekoBot.Migrations table: "IgnoredLogChannels"); migrationBuilder.DropIndex( - name: "IX_IgnoredLogChannels_LogItemId_ItemType", + name: "IX_IgnoredLogChannels_LogSettingId_LogItemId_ItemType", table: "IgnoredLogChannels"); migrationBuilder.DropColumn( @@ -56,6 +72,19 @@ namespace NadekoBot.Migrations table: "IgnoredLogChannels", newName: "ChannelId"); + migrationBuilder.AlterColumn( + name: "LogSettingId", + table: "IgnoredLogChannels", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.CreateIndex( + name: "IX_IgnoredLogChannels_LogSettingId", + table: "IgnoredLogChannels", + column: "LogSettingId"); + migrationBuilder.AddForeignKey( name: "FK_IgnoredLogChannels_LogSettings_LogSettingId", table: "IgnoredLogChannels", diff --git a/src/NadekoBot/Migrations/NadekoContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoContextModelSnapshot.cs index 8c53fc399..b4349bdd0 100644 --- a/src/NadekoBot/Migrations/NadekoContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoContextModelSnapshot.cs @@ -862,14 +862,12 @@ namespace NadekoBot.Migrations b.Property("LogItemId") .HasColumnType("INTEGER"); - b.Property("LogSettingId") + b.Property("LogSettingId") .HasColumnType("INTEGER"); b.HasKey("Id"); - b.HasIndex("LogSettingId"); - - b.HasIndex("LogItemId", "ItemType") + b.HasIndex("LogSettingId", "LogItemId", "ItemType") .IsUnique(); b.ToTable("IgnoredLogChannels"); @@ -2280,7 +2278,8 @@ namespace NadekoBot.Migrations b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") .WithMany("LogIgnores") .HasForeignKey("LogSettingId") - .OnDelete(DeleteBehavior.Cascade); + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("LogSetting"); }); @@ -2288,7 +2287,7 @@ namespace NadekoBot.Migrations modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => { b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") - .WithMany("IgnoredVoicePresenceChannelIds") + .WithMany() .HasForeignKey("LogSettingId"); b.Navigation("LogSetting"); @@ -2605,8 +2604,6 @@ namespace NadekoBot.Migrations modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b => { - b.Navigation("IgnoredVoicePresenceChannelIds"); - b.Navigation("LogIgnores"); });