From 5f0de466a75a8cfc48b7408ff05f6f818eb00da8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 4 Sep 2020 01:08:51 +0100 Subject: [PATCH] Store original filename on import. --- RomRepoMgr.Core/Workers/FileImporter.cs | 19 +- ...00432_AddOriginalFilenameField.Designer.cs | 229 ++++++++++++++++++ ...20200904000432_AddOriginalFilenameField.cs | 13 + .../Migrations/ContextModelSnapshot.cs | 2 + RomRepoMgr.Database/Models/DbFile.cs | 5 +- 5 files changed, 257 insertions(+), 11 deletions(-) create mode 100644 RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.Designer.cs create mode 100644 RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.cs diff --git a/RomRepoMgr.Core/Workers/FileImporter.cs b/RomRepoMgr.Core/Workers/FileImporter.cs index 263498b..e9e9746 100644 --- a/RomRepoMgr.Core/Workers/FileImporter.cs +++ b/RomRepoMgr.Core/Workers/FileImporter.cs @@ -283,15 +283,16 @@ namespace RomRepoMgr.Core.Workers dbFile = new DbFile { - Crc32 = checksums[ChecksumType.Crc32], - Md5 = checksums[ChecksumType.Md5], - Sha1 = checksums[ChecksumType.Sha1], - Sha256 = checksums[ChecksumType.Sha256], - Sha384 = checksums[ChecksumType.Sha384], - Sha512 = checksums[ChecksumType.Sha512], - Size = uSize, - CreatedOn = DateTime.UtcNow, - UpdatedOn = DateTime.UtcNow + Crc32 = checksums[ChecksumType.Crc32], + Md5 = checksums[ChecksumType.Md5], + Sha1 = checksums[ChecksumType.Sha1], + Sha256 = checksums[ChecksumType.Sha256], + Sha384 = checksums[ChecksumType.Sha384], + Sha512 = checksums[ChecksumType.Sha512], + Size = uSize, + CreatedOn = DateTime.UtcNow, + UpdatedOn = DateTime.UtcNow, + OriginalFileName = Path.GetFileName(path) }; fileInDb = false; diff --git a/RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.Designer.cs b/RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.Designer.cs new file mode 100644 index 0000000..4d63b06 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.Designer.cs @@ -0,0 +1,229 @@ +// +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("20200904000432_AddOriginalFilenameField")] + partial class AddOriginalFilenameField + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.7"); + + 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("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Sha384"); + + b.HasIndex("Sha512"); + + b.HasIndex("Size"); + + b.ToTable("Files"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + 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.RomSet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Author") + .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("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.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(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.cs b/RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.cs new file mode 100644 index 0000000..7500844 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200904000432_AddOriginalFilenameField.cs @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace RomRepoMgr.Database.Migrations +{ + public partial class AddOriginalFilenameField : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) => + migrationBuilder.AddColumn("OriginalFileName", "Files", nullable: true); + + protected override void Down(MigrationBuilder migrationBuilder) => + migrationBuilder.DropColumn("OriginalFileName", "Files"); + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs index 30558cd..cc0c371 100644 --- a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs +++ b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs @@ -26,6 +26,8 @@ namespace RomRepoMgr.Database.Migrations 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); diff --git a/RomRepoMgr.Database/Models/DbFile.cs b/RomRepoMgr.Database/Models/DbFile.cs index 040fcf5..3a17f5a 100644 --- a/RomRepoMgr.Database/Models/DbFile.cs +++ b/RomRepoMgr.Database/Models/DbFile.cs @@ -46,7 +46,8 @@ namespace RomRepoMgr.Database.Models [StringLength(128, MinimumLength = 128)] public string Sha512 { get; set; } [DefaultValue(false)] - public bool IsInRepo { get; set; } - public virtual ICollection Machines { get; set; } + public bool IsInRepo { get; set; } + public string OriginalFileName { get; set; } + public virtual ICollection Machines { get; set; } } } \ No newline at end of file