Re-did migration as the old one was wrong

This commit is contained in:
Kwoth
2021-09-21 22:48:18 +02:00
parent c9e89e1911
commit 453ac3efd2
5 changed files with 47 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
{ {
public class IgnoredLogItem : DbEntity public class IgnoredLogItem : DbEntity
{ {
public int LogSettingId { get; set; }
public LogSetting LogSetting { get; set; } public LogSetting LogSetting { get; set; }
public ulong LogItemId { get; set; } public ulong LogItemId { get; set; }
public IgnoredItemType ItemType { get; set; } public IgnoredItemType ItemType { get; set; }

View File

@@ -349,7 +349,7 @@ namespace NadekoBot.Services.Database
.OnDelete(DeleteBehavior.Cascade)); .OnDelete(DeleteBehavior.Cascade));
modelBuilder.Entity<IgnoredLogItem>(ili => ili modelBuilder.Entity<IgnoredLogItem>(ili => ili
.HasIndex(x => new { ItemId = x.LogItemId, x.ItemType }) .HasIndex(x => new { x.LogSettingId, x.LogItemId, x.ItemType })
.IsUnique()); .IsUnique());
#endregion #endregion

View File

@@ -9,8 +9,8 @@ using NadekoBot.Services.Database;
namespace NadekoBot.Migrations namespace NadekoBot.Migrations
{ {
[DbContext(typeof(NadekoContext))] [DbContext(typeof(NadekoContext))]
[Migration("20210921194708_logignore-user-role-channel")] [Migration("20210921204645_logignore-user-channel")]
partial class logignoreuserrolechannel partial class logignoreuserchannel
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
@@ -864,14 +864,12 @@ namespace NadekoBot.Migrations
b.Property<ulong>("LogItemId") b.Property<ulong>("LogItemId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int?>("LogSettingId") b.Property<int>("LogSettingId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("LogSettingId"); b.HasIndex("LogSettingId", "LogItemId", "ItemType")
b.HasIndex("LogItemId", "ItemType")
.IsUnique(); .IsUnique();
b.ToTable("IgnoredLogChannels"); b.ToTable("IgnoredLogChannels");
@@ -2282,7 +2280,8 @@ namespace NadekoBot.Migrations
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
.WithMany("LogIgnores") .WithMany("LogIgnores")
.HasForeignKey("LogSettingId") .HasForeignKey("LogSettingId")
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LogSetting"); b.Navigation("LogSetting");
}); });
@@ -2290,7 +2289,7 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
.WithMany("IgnoredVoicePresenceChannelIds") .WithMany()
.HasForeignKey("LogSettingId"); .HasForeignKey("LogSettingId");
b.Navigation("LogSetting"); b.Navigation("LogSetting");
@@ -2607,8 +2606,6 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b =>
{ {
b.Navigation("IgnoredVoicePresenceChannelIds");
b.Navigation("LogIgnores"); b.Navigation("LogIgnores");
}); });

View File

@@ -2,19 +2,35 @@
namespace NadekoBot.Migrations namespace NadekoBot.Migrations
{ {
public partial class logignoreuserrolechannel : Migration public partial class logignoreuserchannel : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.Sql("DELETE FROM IgnoredLogChannels WHERE LogSettingId is NULL");
migrationBuilder.DropForeignKey( migrationBuilder.DropForeignKey(
name: "FK_IgnoredLogChannels_LogSettings_LogSettingId", name: "FK_IgnoredLogChannels_LogSettings_LogSettingId",
table: "IgnoredLogChannels"); table: "IgnoredLogChannels");
migrationBuilder.DropIndex(
name: "IX_IgnoredLogChannels_LogSettingId",
table: "IgnoredLogChannels");
migrationBuilder.RenameColumn( migrationBuilder.RenameColumn(
name: "ChannelId", name: "ChannelId",
table: "IgnoredLogChannels", table: "IgnoredLogChannels",
newName: "LogItemId"); newName: "LogItemId");
migrationBuilder.AlterColumn<int>(
name: "LogSettingId",
table: "IgnoredLogChannels",
type: "INTEGER",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "INTEGER",
oldNullable: true);
migrationBuilder.AddColumn<int>( migrationBuilder.AddColumn<int>(
name: "ItemType", name: "ItemType",
table: "IgnoredLogChannels", table: "IgnoredLogChannels",
@@ -23,9 +39,9 @@ namespace NadekoBot.Migrations
defaultValue: 0); defaultValue: 0);
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_IgnoredLogChannels_LogItemId_ItemType", name: "IX_IgnoredLogChannels_LogSettingId_LogItemId_ItemType",
table: "IgnoredLogChannels", table: "IgnoredLogChannels",
columns: new[] { "LogItemId", "ItemType" }, columns: new[] { "LogSettingId", "LogItemId", "ItemType" },
unique: true); unique: true);
migrationBuilder.AddForeignKey( migrationBuilder.AddForeignKey(
@@ -44,7 +60,7 @@ namespace NadekoBot.Migrations
table: "IgnoredLogChannels"); table: "IgnoredLogChannels");
migrationBuilder.DropIndex( migrationBuilder.DropIndex(
name: "IX_IgnoredLogChannels_LogItemId_ItemType", name: "IX_IgnoredLogChannels_LogSettingId_LogItemId_ItemType",
table: "IgnoredLogChannels"); table: "IgnoredLogChannels");
migrationBuilder.DropColumn( migrationBuilder.DropColumn(
@@ -56,6 +72,19 @@ namespace NadekoBot.Migrations
table: "IgnoredLogChannels", table: "IgnoredLogChannels",
newName: "ChannelId"); newName: "ChannelId");
migrationBuilder.AlterColumn<int>(
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( migrationBuilder.AddForeignKey(
name: "FK_IgnoredLogChannels_LogSettings_LogSettingId", name: "FK_IgnoredLogChannels_LogSettings_LogSettingId",
table: "IgnoredLogChannels", table: "IgnoredLogChannels",

View File

@@ -862,14 +862,12 @@ namespace NadekoBot.Migrations
b.Property<ulong>("LogItemId") b.Property<ulong>("LogItemId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int?>("LogSettingId") b.Property<int>("LogSettingId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("LogSettingId"); b.HasIndex("LogSettingId", "LogItemId", "ItemType")
b.HasIndex("LogItemId", "ItemType")
.IsUnique(); .IsUnique();
b.ToTable("IgnoredLogChannels"); b.ToTable("IgnoredLogChannels");
@@ -2280,7 +2278,8 @@ namespace NadekoBot.Migrations
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
.WithMany("LogIgnores") .WithMany("LogIgnores")
.HasForeignKey("LogSettingId") .HasForeignKey("LogSettingId")
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LogSetting"); b.Navigation("LogSetting");
}); });
@@ -2288,7 +2287,7 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
.WithMany("IgnoredVoicePresenceChannelIds") .WithMany()
.HasForeignKey("LogSettingId"); .HasForeignKey("LogSettingId");
b.Navigation("LogSetting"); b.Navigation("LogSetting");
@@ -2605,8 +2604,6 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b =>
{ {
b.Navigation("IgnoredVoicePresenceChannelIds");
b.Navigation("LogIgnores"); b.Navigation("LogIgnores");
}); });