diff --git a/RomRepoMgr.Database/Context.cs b/RomRepoMgr.Database/Context.cs index eb8d055..725c448 100644 --- a/RomRepoMgr.Database/Context.cs +++ b/RomRepoMgr.Database/Context.cs @@ -77,6 +77,42 @@ namespace RomRepoMgr.Database entity.HasIndex(e => e.Size); entity.HasIndex(e => e.IsInRepo); + + entity.HasIndex(e => new + { + e.Crc32, + e.Size + }); + + entity.HasIndex(e => new + { + e.Md5, + e.Size + }); + + entity.HasIndex(e => new + { + e.Sha1, + e.Size + }); + + entity.HasIndex(e => new + { + e.Sha256, + e.Size + }); + + entity.HasIndex(e => new + { + e.Sha384, + e.Size + }); + + entity.HasIndex(e => new + { + e.Sha512, + e.Size + }); }); modelBuilder.Entity(entity => diff --git a/RomRepoMgr.Database/Migrations/20200911005409_AddCompositeIndexes.Designer.cs b/RomRepoMgr.Database/Migrations/20200911005409_AddCompositeIndexes.Designer.cs new file mode 100644 index 0000000..c6e82bf --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200911005409_AddCompositeIndexes.Designer.cs @@ -0,0 +1,473 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using RomRepoMgr.Database; + +namespace RomRepoMgr.Database.Migrations +{ + [DbContext(typeof(Context))] + [Migration("20200911005409_AddCompositeIndexes")] + partial class AddCompositeIndexes + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.7"); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DbDisk", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("IsInRepo") + .HasColumnType("INTEGER"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("OriginalFileName") + .HasColumnType("TEXT"); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsInRepo"); + + b.HasIndex("Md5"); + + b.HasIndex("Sha1"); + + b.HasIndex("Size"); + + b.ToTable("Disks"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DbFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Crc32") + .HasColumnType("TEXT") + .HasMaxLength(8); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("IsInRepo") + .HasColumnType("INTEGER"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("OriginalFileName") + .HasColumnType("TEXT"); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Sha256") + .HasColumnType("TEXT") + .HasMaxLength(64); + + b.Property("Sha384") + .HasColumnType("TEXT") + .HasMaxLength(96); + + b.Property("Sha512") + .HasColumnType("TEXT") + .HasMaxLength(128); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Crc32"); + + b.HasIndex("IsInRepo"); + + b.HasIndex("Md5"); + + b.HasIndex("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Sha384"); + + b.HasIndex("Sha512"); + + b.HasIndex("Size"); + + b.HasIndex("Crc32", "Size"); + + b.HasIndex("Md5", "Size"); + + b.HasIndex("Sha1", "Size"); + + b.HasIndex("Sha256", "Size"); + + b.HasIndex("Sha384", "Size"); + + b.HasIndex("Sha512", "Size"); + + b.ToTable("Files"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DbMedia", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("IsInRepo") + .HasColumnType("INTEGER"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("OriginalFileName") + .HasColumnType("TEXT"); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Sha256") + .HasColumnType("TEXT") + .HasMaxLength(64); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("SpamSum") + .HasColumnType("TEXT"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsInRepo"); + + b.HasIndex("Md5"); + + b.HasIndex("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Size"); + + b.HasIndex("SpamSum"); + + b.ToTable("Medias"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DiskByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiskId") + .HasColumnType("INTEGER"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("DiskId"); + + b.HasIndex("MachineId"); + + b.HasIndex("Name"); + + b.ToTable("DisksByMachines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("FileLastModification") + .HasColumnType("TEXT"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Path") + .HasColumnType("TEXT") + .HasMaxLength(4096); + + b.HasKey("Id"); + + b.HasIndex("FileId"); + + b.HasIndex("MachineId"); + + b.HasIndex("Name"); + + b.ToTable("FilesByMachines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RomSetId") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.HasIndex("RomSetId"); + + b.ToTable("Machines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.MediaByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("MediaId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MachineId"); + + b.HasIndex("MediaId"); + + b.HasIndex("Name"); + + b.ToTable("MediasByMachines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Author") + .HasColumnType("TEXT"); + + b.Property("Category") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Filename") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Homepage") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Sha384") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(96); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.Property("Version") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Author"); + + b.HasIndex("Category"); + + b.HasIndex("Comment"); + + b.HasIndex("Date"); + + b.HasIndex("Description"); + + b.HasIndex("Filename"); + + b.HasIndex("Homepage"); + + b.HasIndex("Name"); + + b.HasIndex("Sha384"); + + b.HasIndex("Version"); + + b.ToTable("RomSets"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.RomSetStat", b => + { + b.Property("RomSetId") + .HasColumnType("INTEGER"); + + b.Property("CompleteMachines") + .HasColumnType("INTEGER"); + + b.Property("HaveRoms") + .HasColumnType("INTEGER"); + + b.Property("IncompleteMachines") + .HasColumnType("INTEGER"); + + b.Property("MissRoms") + .HasColumnType("INTEGER"); + + b.Property("TotalMachines") + .HasColumnType("INTEGER"); + + b.Property("TotalRoms") + .HasColumnType("INTEGER"); + + b.HasKey("RomSetId"); + + b.ToTable("RomSetStats"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DiskByMachine", b => + { + b.HasOne("RomRepoMgr.Database.Models.DbDisk", "Disk") + .WithMany("Machines") + .HasForeignKey("DiskId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RomRepoMgr.Database.Models.Machine", "Machine") + .WithMany("Disks") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b => + { + b.HasOne("RomRepoMgr.Database.Models.DbFile", "File") + .WithMany("Machines") + .HasForeignKey("FileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RomRepoMgr.Database.Models.Machine", "Machine") + .WithMany("Files") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b => + { + b.HasOne("RomRepoMgr.Database.Models.RomSet", "RomSet") + .WithMany("Machines") + .HasForeignKey("RomSetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.MediaByMachine", b => + { + b.HasOne("RomRepoMgr.Database.Models.Machine", "Machine") + .WithMany("Medias") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RomRepoMgr.Database.Models.DbMedia", "Media") + .WithMany("Machines") + .HasForeignKey("MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.RomSetStat", b => + { + b.HasOne("RomRepoMgr.Database.Models.RomSet", "RomSet") + .WithOne("Statistics") + .HasForeignKey("RomRepoMgr.Database.Models.RomSetStat", "RomSetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RomRepoMgr.Database/Migrations/20200911005409_AddCompositeIndexes.cs b/RomRepoMgr.Database/Migrations/20200911005409_AddCompositeIndexes.cs new file mode 100644 index 0000000..a41157a --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200911005409_AddCompositeIndexes.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace RomRepoMgr.Database.Migrations +{ + public partial class AddCompositeIndexes : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex("IX_Files_Crc32_Size", "Files", new[] + { + "Crc32", "Size" + }); + + migrationBuilder.CreateIndex("IX_Files_Md5_Size", "Files", new[] + { + "Md5", "Size" + }); + + migrationBuilder.CreateIndex("IX_Files_Sha1_Size", "Files", new[] + { + "Sha1", "Size" + }); + + migrationBuilder.CreateIndex("IX_Files_Sha256_Size", "Files", new[] + { + "Sha256", "Size" + }); + + migrationBuilder.CreateIndex("IX_Files_Sha384_Size", "Files", new[] + { + "Sha384", "Size" + }); + + migrationBuilder.CreateIndex("IX_Files_Sha512_Size", "Files", new[] + { + "Sha512", "Size" + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex("IX_Files_Crc32_Size", "Files"); + + migrationBuilder.DropIndex("IX_Files_Md5_Size", "Files"); + + migrationBuilder.DropIndex("IX_Files_Sha1_Size", "Files"); + + migrationBuilder.DropIndex("IX_Files_Sha256_Size", "Files"); + + migrationBuilder.DropIndex("IX_Files_Sha384_Size", "Files"); + + migrationBuilder.DropIndex("IX_Files_Sha512_Size", "Files"); + } + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs index 474f8c1..6ab506b 100644 --- a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs +++ b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs @@ -89,6 +89,18 @@ namespace RomRepoMgr.Database.Migrations b.HasIndex("Size"); + b.HasIndex("Crc32", "Size"); + + b.HasIndex("Md5", "Size"); + + b.HasIndex("Sha1", "Size"); + + b.HasIndex("Sha256", "Size"); + + b.HasIndex("Sha384", "Size"); + + b.HasIndex("Sha512", "Size"); + b.ToTable("Files"); });