diff --git a/RomRepoMgr.Database/Context.cs b/RomRepoMgr.Database/Context.cs index 3b00e7e..0852a12 100644 --- a/RomRepoMgr.Database/Context.cs +++ b/RomRepoMgr.Database/Context.cs @@ -1,36 +1,30 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite +/****************************************************************************** +// RomRepoMgr - ROM repository manager // ---------------------------------------------------------------------------- // -// Filename : Context.cs // Author(s) : Natalia Portillo // -// Component : Database. -// -// --[ Description ] ---------------------------------------------------------- -// -// Entity framework database context. -// // --[ License ] -------------------------------------------------------------- // -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the +// 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 library 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 -// Lesser General Public License for more details. +// 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 Lesser General Public -// License along with this library; if not, see . +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo -// ****************************************************************************/ +// Copyright © 2020 Natalia Portillo +*******************************************************************************/ using Microsoft.EntityFrameworkCore; +using RomRepoMgr.Database.Models; namespace RomRepoMgr.Database { @@ -38,6 +32,8 @@ namespace RomRepoMgr.Database { public Context(DbContextOptions options) : base(options) {} + public DbSet Files { get; set; } + public static Context Create(string dbPath) { var optionsBuilder = new DbContextOptionsBuilder(); @@ -46,11 +42,20 @@ namespace RomRepoMgr.Database return new Context(optionsBuilder.Options); } - /* - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - } - */ + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity(entity => + { + entity.HasIndex(e => e.Crc32); + + entity.HasIndex(e => e.Sha1); + + entity.HasIndex(e => e.Sha256); + + entity.HasIndex(e => e.Size); + }); + } } } \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/20200821223117_AddFiles.Designer.cs b/RomRepoMgr.Database/Migrations/20200821223117_AddFiles.Designer.cs new file mode 100644 index 0000000..d052e3a --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200821223117_AddFiles.Designer.cs @@ -0,0 +1,69 @@ +// +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("20200821223117_AddFiles")] + partial class AddFiles + { + 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") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Sha256") + .HasColumnType("TEXT") + .HasMaxLength(64); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Crc32"); + + b.HasIndex("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Size"); + + b.ToTable("Files"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RomRepoMgr.Database/Migrations/20200821223117_AddFiles.cs b/RomRepoMgr.Database/Migrations/20200821223117_AddFiles.cs new file mode 100644 index 0000000..1dd0554 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200821223117_AddFiles.cs @@ -0,0 +1,61 @@ +/****************************************************************************** +// RomRepoMgr - ROM repository manager +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2020 Natalia Portillo +*******************************************************************************/ + +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace RomRepoMgr.Database.Migrations +{ + public partial class AddFiles : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable("Files", table => new + { + Id = table.Column(nullable: false).Annotation("Sqlite:Autoincrement", true), + CreatedOn = table.Column(nullable: false), + UpdatedOn = table.Column(nullable: false), + Size = table.Column(nullable: false), + Crc32 = table.Column(maxLength: 8, nullable: true), + Md5 = table.Column(maxLength: 32, nullable: true), + Sha1 = table.Column(maxLength: 40, nullable: true), + Sha256 = table.Column(maxLength: 64, nullable: true) + }, constraints: table => + { + table.PrimaryKey("PK_Files", x => x.Id); + }); + + migrationBuilder.CreateIndex("IX_Files_Crc32", "Files", "Crc32"); + + migrationBuilder.CreateIndex("IX_Files_Sha1", "Files", "Sha1"); + + migrationBuilder.CreateIndex("IX_Files_Sha256", "Files", "Sha256"); + + migrationBuilder.CreateIndex("IX_Files_Size", "Files", "Size"); + } + + protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable("Files"); + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs index fe55500..5ca1f59 100644 --- a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs +++ b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs @@ -1,5 +1,6 @@ // +using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -12,6 +13,37 @@ namespace RomRepoMgr.Database.Migrations { #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").ValueGeneratedOnAdd().HasColumnType("TEXT"); + + b.Property("Md5").HasColumnType("TEXT").HasMaxLength(32); + + b.Property("Sha1").HasColumnType("TEXT").HasMaxLength(40); + + b.Property("Sha256").HasColumnType("TEXT").HasMaxLength(64); + + b.Property("Size").HasColumnType("INTEGER"); + + b.Property("UpdatedOn").ValueGeneratedOnAddOrUpdate().HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Crc32"); + + b.HasIndex("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Size"); + + b.ToTable("Files"); + }); #pragma warning restore 612, 618 } } diff --git a/RomRepoMgr.Database/Models/BaseModel.cs b/RomRepoMgr.Database/Models/BaseModel.cs new file mode 100644 index 0000000..bbd840d --- /dev/null +++ b/RomRepoMgr.Database/Models/BaseModel.cs @@ -0,0 +1,40 @@ +/****************************************************************************** +// RomRepoMgr - ROM repository manager +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2020 Natalia Portillo +*******************************************************************************/ + +using System; +using System.ComponentModel.DataAnnotations.Schema; + +namespace RomRepoMgr.Database.Models +{ + public abstract class BaseModel + { + public TKey Id { get; set; } + + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public DateTime CreatedOn { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Computed)] + public DateTime UpdatedOn { get; set; } + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Models/DbFile.cs b/RomRepoMgr.Database/Models/DbFile.cs new file mode 100644 index 0000000..e5cb0f7 --- /dev/null +++ b/RomRepoMgr.Database/Models/DbFile.cs @@ -0,0 +1,43 @@ +/****************************************************************************** +// RomRepoMgr - ROM repository manager +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2020 Natalia Portillo +*******************************************************************************/ + +using System.ComponentModel.DataAnnotations; + +namespace RomRepoMgr.Database.Models +{ + public class DbFile : BaseModel + { + [Required] + public ulong Size { get; set; } + [StringLength(8, MinimumLength = 8)] + public string Crc32 { get; set; } + [StringLength(32, MinimumLength = 32)] + public string Md5 { get; set; } + [StringLength(40, MinimumLength = 40)] + public string Sha1 { get; set; } + [StringLength(64, MinimumLength = 64)] + public string Sha256 { get; set; } + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/RomRepoMgr.Database.csproj b/RomRepoMgr.Database/RomRepoMgr.Database.csproj index cfaf089..f205303 100644 --- a/RomRepoMgr.Database/RomRepoMgr.Database.csproj +++ b/RomRepoMgr.Database/RomRepoMgr.Database.csproj @@ -16,7 +16,6 @@ -