Create disk entity for database.

This commit is contained in:
2020-09-04 02:12:38 +01:00
parent 1caca29060
commit fc675fd764
7 changed files with 535 additions and 0 deletions

View File

@@ -58,6 +58,8 @@ namespace RomRepoMgr.Database
public DbSet<RomSet> RomSets { get; set; } public DbSet<RomSet> RomSets { get; set; }
public DbSet<Machine> Machines { get; set; } public DbSet<Machine> Machines { get; set; }
public DbSet<FileByMachine> FilesByMachines { get; set; } public DbSet<FileByMachine> FilesByMachines { get; set; }
public DbSet<DbDisk> Disks { get; set; }
public DbSet<DiskByMachine> DisksByMachines { get; set; }
public static void ReplaceSingleton(string dbPath) => _singleton = Create(dbPath); public static void ReplaceSingleton(string dbPath) => _singleton = Create(dbPath);
@@ -129,6 +131,24 @@ namespace RomRepoMgr.Database
entity.HasOne(e => e.File).WithMany(e => e.Machines).OnDelete(DeleteBehavior.Cascade); entity.HasOne(e => e.File).WithMany(e => e.Machines).OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity<DbDisk>(entity =>
{
entity.HasIndex(e => e.Md5);
entity.HasIndex(e => e.Sha1);
entity.HasIndex(e => e.Size);
});
modelBuilder.Entity<DiskByMachine>(entity =>
{
entity.HasIndex(e => e.Name);
entity.HasOne(e => e.Machine).WithMany(e => e.Disks).OnDelete(DeleteBehavior.Cascade);
entity.HasOne(e => e.Disk).WithMany(e => e.Machines).OnDelete(DeleteBehavior.Cascade);
});
} }
} }
} }

View File

@@ -0,0 +1,311 @@
// <auto-generated />
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("20200904011014_AddDisks")]
partial class AddDisks
{
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<ulong>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedOn")
.HasColumnType("TEXT");
b.Property<bool>("IsInRepo")
.HasColumnType("INTEGER");
b.Property<string>("Md5")
.HasColumnType("TEXT")
.HasMaxLength(32);
b.Property<string>("OriginalFileName")
.HasColumnType("TEXT");
b.Property<string>("Sha1")
.HasColumnType("TEXT")
.HasMaxLength(40);
b.Property<ulong?>("Size")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedOn")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Md5");
b.HasIndex("Sha1");
b.HasIndex("Size");
b.ToTable("Disks");
});
modelBuilder.Entity("RomRepoMgr.Database.Models.DbFile", b =>
{
b.Property<ulong>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Crc32")
.HasColumnType("TEXT")
.HasMaxLength(8);
b.Property<DateTime>("CreatedOn")
.HasColumnType("TEXT");
b.Property<bool>("IsInRepo")
.HasColumnType("INTEGER");
b.Property<string>("Md5")
.HasColumnType("TEXT")
.HasMaxLength(32);
b.Property<string>("OriginalFileName")
.HasColumnType("TEXT");
b.Property<string>("Sha1")
.HasColumnType("TEXT")
.HasMaxLength(40);
b.Property<string>("Sha256")
.HasColumnType("TEXT")
.HasMaxLength(64);
b.Property<string>("Sha384")
.HasColumnType("TEXT")
.HasMaxLength(96);
b.Property<string>("Sha512")
.HasColumnType("TEXT")
.HasMaxLength(128);
b.Property<ulong>("Size")
.HasColumnType("INTEGER");
b.Property<DateTime>("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.DiskByMachine", b =>
{
b.Property<ulong>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<ulong>("DiskId")
.HasColumnType("INTEGER");
b.Property<ulong>("MachineId")
.HasColumnType("INTEGER");
b.Property<string>("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<ulong>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<ulong>("FileId")
.HasColumnType("INTEGER");
b.Property<ulong>("MachineId")
.HasColumnType("INTEGER");
b.Property<string>("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<ulong>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedOn")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<long>("RomSetId")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedOn")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Name");
b.HasIndex("RomSetId");
b.ToTable("Machines");
});
modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Author")
.HasColumnType("TEXT");
b.Property<string>("Comment")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedOn")
.HasColumnType("TEXT");
b.Property<string>("Date")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Filename")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Homepage")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Sha384")
.IsRequired()
.HasColumnType("TEXT")
.HasMaxLength(96);
b.Property<DateTime>("UpdatedOn")
.HasColumnType("TEXT");
b.Property<string>("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.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();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace RomRepoMgr.Database.Migrations
{
public partial class AddDisks : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable("Disks", table => new
{
Id = table.Column<ulong>(nullable: false).Annotation("Sqlite:Autoincrement", true),
CreatedOn = table.Column<DateTime>(nullable: false),
UpdatedOn = table.Column<DateTime>(nullable: false),
Size = table.Column<ulong>(nullable: true),
Md5 = table.Column<string>(maxLength: 32, nullable: true),
Sha1 = table.Column<string>(maxLength: 40, nullable: true),
IsInRepo = table.Column<bool>(nullable: false),
OriginalFileName = table.Column<string>(nullable: true)
}, constraints: table => table.PrimaryKey("PK_Disks", x => x.Id));
migrationBuilder.CreateTable("DisksByMachines", table => new
{
Id = table.Column<ulong>(nullable: false).Annotation("Sqlite:Autoincrement", true),
DiskId = table.Column<ulong>(nullable: false),
MachineId = table.Column<ulong>(nullable: false),
Name = table.Column<string>(nullable: false)
}, constraints: table =>
{
table.PrimaryKey("PK_DisksByMachines", x => x.Id);
table.ForeignKey("FK_DisksByMachines_Disks_DiskId", x => x.DiskId, "Disks", "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey("FK_DisksByMachines_Machines_MachineId", x => x.MachineId, "Machines", "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex("IX_Disks_Md5", "Disks", "Md5");
migrationBuilder.CreateIndex("IX_Disks_Sha1", "Disks", "Sha1");
migrationBuilder.CreateIndex("IX_Disks_Size", "Disks", "Size");
migrationBuilder.CreateIndex("IX_DisksByMachines_DiskId", "DisksByMachines", "DiskId");
migrationBuilder.CreateIndex("IX_DisksByMachines_MachineId", "DisksByMachines", "MachineId");
migrationBuilder.CreateIndex("IX_DisksByMachines_Name", "DisksByMachines", "Name");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable("DisksByMachines");
migrationBuilder.DropTable("Disks");
}
}
}

View File

@@ -14,6 +14,35 @@ namespace RomRepoMgr.Database.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "3.1.7"); modelBuilder.HasAnnotation("ProductVersion", "3.1.7");
modelBuilder.Entity("RomRepoMgr.Database.Models.DbDisk", b =>
{
b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<DateTime>("CreatedOn").HasColumnType("TEXT");
b.Property<bool>("IsInRepo").HasColumnType("INTEGER");
b.Property<string>("Md5").HasColumnType("TEXT").HasMaxLength(32);
b.Property<string>("OriginalFileName").HasColumnType("TEXT");
b.Property<string>("Sha1").HasColumnType("TEXT").HasMaxLength(40);
b.Property<ulong?>("Size").HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedOn").HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Md5");
b.HasIndex("Sha1");
b.HasIndex("Size");
b.ToTable("Disks");
});
modelBuilder.Entity("RomRepoMgr.Database.Models.DbFile", b => modelBuilder.Entity("RomRepoMgr.Database.Models.DbFile", b =>
{ {
b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER"); b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
@@ -57,6 +86,27 @@ namespace RomRepoMgr.Database.Migrations
b.ToTable("Files"); b.ToTable("Files");
}); });
modelBuilder.Entity("RomRepoMgr.Database.Models.DiskByMachine", b =>
{
b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<ulong>("DiskId").HasColumnType("INTEGER");
b.Property<ulong>("MachineId").HasColumnType("INTEGER");
b.Property<string>("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 => modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b =>
{ {
b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER"); b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
@@ -148,6 +198,15 @@ namespace RomRepoMgr.Database.Migrations
b.ToTable("RomSets"); b.ToTable("RomSets");
}); });
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 => modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b =>
{ {
b.HasOne("RomRepoMgr.Database.Models.DbFile", "File").WithMany("Machines").HasForeignKey("FileId"). b.HasOne("RomRepoMgr.Database.Models.DbFile", "File").WithMany("Machines").HasForeignKey("FileId").

View File

@@ -0,0 +1,44 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace RomRepoMgr.Database.Models
{
public class DbDisk : BaseModel<ulong>
{
public ulong? Size { get; set; }
[StringLength(32, MinimumLength = 32)]
public string Md5 { get; set; }
[StringLength(40, MinimumLength = 40)]
public string Sha1 { get; set; }
[DefaultValue(false)]
public bool IsInRepo { get; set; }
public string OriginalFileName { get; set; }
public virtual ICollection<DiskByMachine> Machines { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using System.ComponentModel.DataAnnotations;
namespace RomRepoMgr.Database.Models
{
public class DiskByMachine
{
[Key]
public ulong Id { get; set; }
[Required]
public virtual DbDisk Disk { get; set; }
[Required]
public virtual Machine Machine { get; set; }
[Required]
public string Name { get; set; }
}
}

View File

@@ -35,5 +35,6 @@ namespace RomRepoMgr.Database.Models
[Required] [Required]
public virtual RomSet RomSet { get; set; } public virtual RomSet RomSet { get; set; }
public virtual ICollection<FileByMachine> Files { get; set; } public virtual ICollection<FileByMachine> Files { get; set; }
public virtual ICollection<DiskByMachine> Disks { get; set; }
} }
} }