From e7373d8bb1a9c3d27a53e5cc61a803ec5fb952ed Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 21 Aug 2020 23:21:01 +0100 Subject: [PATCH] Add database. --- RomRepoMgr.Database/Context.cs | 56 +++++++++++++++++++ RomRepoMgr.Database/ContextFactory.cs | 9 +++ ...0200821221812_InitialMigration.Designer.cs | 22 ++++++++ .../20200821221812_InitialMigration.cs | 11 ++++ .../Migrations/ContextModelSnapshot.cs | 18 ++++++ .../RomRepoMgr.Database.csproj | 22 ++++++++ RomRepoMgr.sln | 6 ++ RomRepoMgr/RomRepoMgr.csproj | 10 ++-- 8 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 RomRepoMgr.Database/Context.cs create mode 100644 RomRepoMgr.Database/ContextFactory.cs create mode 100644 RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.Designer.cs create mode 100644 RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.cs create mode 100644 RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs create mode 100644 RomRepoMgr.Database/RomRepoMgr.Database.csproj diff --git a/RomRepoMgr.Database/Context.cs b/RomRepoMgr.Database/Context.cs new file mode 100644 index 0000000..3b00e7e --- /dev/null +++ b/RomRepoMgr.Database/Context.cs @@ -0,0 +1,56 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// 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 +// 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. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2020 Natalia Portillo +// ****************************************************************************/ + +using Microsoft.EntityFrameworkCore; + +namespace RomRepoMgr.Database +{ + public sealed class Context : DbContext + { + public Context(DbContextOptions options) : base(options) {} + + public static Context Create(string dbPath) + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseLazyLoadingProxies().UseSqlite($"Data Source={dbPath}"); + + return new Context(optionsBuilder.Options); + } + + /* + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + } + */ + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/ContextFactory.cs b/RomRepoMgr.Database/ContextFactory.cs new file mode 100644 index 0000000..ecd9ff1 --- /dev/null +++ b/RomRepoMgr.Database/ContextFactory.cs @@ -0,0 +1,9 @@ +using Microsoft.EntityFrameworkCore.Design; + +namespace RomRepoMgr.Database +{ + public class ContextFactory : IDesignTimeDbContextFactory + { + public Context CreateDbContext(string[] args) => Context.Create("romrepo.db"); + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.Designer.cs b/RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.Designer.cs new file mode 100644 index 0000000..e328fb6 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.Designer.cs @@ -0,0 +1,22 @@ +// +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("20200821221812_InitialMigration")] + partial class InitialMigration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.7"); +#pragma warning restore 612, 618 + } + } +} diff --git a/RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.cs b/RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.cs new file mode 100644 index 0000000..f0465a6 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200821221812_InitialMigration.cs @@ -0,0 +1,11 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace RomRepoMgr.Database.Migrations +{ + public partial class InitialMigration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) {} + + protected override void Down(MigrationBuilder migrationBuilder) {} + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs new file mode 100644 index 0000000..fe55500 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs @@ -0,0 +1,18 @@ +// + +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; + +namespace RomRepoMgr.Database.Migrations +{ + [DbContext(typeof(Context))] + internal class ContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + #pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "3.1.7"); + #pragma warning restore 612, 618 + } + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/RomRepoMgr.Database.csproj b/RomRepoMgr.Database/RomRepoMgr.Database.csproj new file mode 100644 index 0000000..cfaf089 --- /dev/null +++ b/RomRepoMgr.Database/RomRepoMgr.Database.csproj @@ -0,0 +1,22 @@ + + + + netcoreapp3.1 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/RomRepoMgr.sln b/RomRepoMgr.sln index 3a84774..53f794c 100644 --- a/RomRepoMgr.sln +++ b/RomRepoMgr.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RomRepoMgr", "RomRepoMgr\RomRepoMgr.csproj", "{6CDCA6AF-B060-45AC-BCE2-CDBB0AF6B9AE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RomRepoMgr.Database", "RomRepoMgr.Database\RomRepoMgr.Database.csproj", "{FE5ACD61-90F1-4B9F-9BDA-50934040882A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {6CDCA6AF-B060-45AC-BCE2-CDBB0AF6B9AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {6CDCA6AF-B060-45AC-BCE2-CDBB0AF6B9AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {6CDCA6AF-B060-45AC-BCE2-CDBB0AF6B9AE}.Release|Any CPU.Build.0 = Release|Any CPU + {FE5ACD61-90F1-4B9F-9BDA-50934040882A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE5ACD61-90F1-4B9F-9BDA-50934040882A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE5ACD61-90F1-4B9F-9BDA-50934040882A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE5ACD61-90F1-4B9F-9BDA-50934040882A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/RomRepoMgr/RomRepoMgr.csproj b/RomRepoMgr/RomRepoMgr.csproj index a61737f..f23d407 100644 --- a/RomRepoMgr/RomRepoMgr.csproj +++ b/RomRepoMgr/RomRepoMgr.csproj @@ -4,18 +4,18 @@ netcoreapp3.0 - + %(Filename) Designer - + - - - + + +