From 84e7ec274cece36d63fa3ccc1b055256ace3cddd Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 15 Nov 2024 16:29:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=81=D0=BB=D0=BE=D0=B9=20Persistence.Database.Postgr?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Persistence.API/Persistence.API.csproj | 1 + Persistence.API/Program.cs | 9 +- Persistence.API/Startup.cs | 17 ++- .../DependencyInjection.cs | 22 ++++ .../EFExtensionsInitialization.cs | 2 +- .../20241115105149_InitialCreate.Designer.cs | 122 ++++++++++++++++++ .../20241115105149_InitialCreate.cs | 56 ++++++++ .../PersistenceDbContextModelSnapshot.cs | 119 +++++++++++++++++ .../Persistence.Database.Postgres.csproj | 21 +++ .../PersistenceDbContext.cs | 32 +++-- Persistence.Database.Postgres/Readme.md | 5 + .../{Model => Entity}/DataSaub.cs | 0 .../{Model => Entity}/ITimestampedData.cs | 0 Persistence.Database/IPersistenceDbContext.cs | 8 ++ .../Model/IDbContextManager.cs | 21 --- .../Model/IPersistenceDbContext.cs | 16 --- .../Persistence.Database.csproj | 2 +- Persistence.Repository/DependencyInjection.cs | 11 +- .../Repositories/TimeSeriesDataRepository.cs | 5 +- Persistence.Repository/Startup.cs | 19 --- Persistence.sln | 8 +- 21 files changed, 408 insertions(+), 88 deletions(-) create mode 100644 Persistence.Database.Postgres/DependencyInjection.cs rename {Persistence.Database => Persistence.Database.Postgres}/EFExtensionsInitialization.cs (98%) create mode 100644 Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.Designer.cs create mode 100644 Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.cs create mode 100644 Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs create mode 100644 Persistence.Database.Postgres/Persistence.Database.Postgres.csproj rename {Persistence.Database/Model => Persistence.Database.Postgres}/PersistenceDbContext.cs (71%) create mode 100644 Persistence.Database.Postgres/Readme.md rename Persistence.Database/{Model => Entity}/DataSaub.cs (100%) rename Persistence.Database/{Model => Entity}/ITimestampedData.cs (100%) create mode 100644 Persistence.Database/IPersistenceDbContext.cs delete mode 100644 Persistence.Database/Model/IDbContextManager.cs delete mode 100644 Persistence.Database/Model/IPersistenceDbContext.cs delete mode 100644 Persistence.Repository/Startup.cs diff --git a/Persistence.API/Persistence.API.csproj b/Persistence.API/Persistence.API.csproj index f71c59d..40bed8a 100644 --- a/Persistence.API/Persistence.API.csproj +++ b/Persistence.API/Persistence.API.csproj @@ -13,6 +13,7 @@ + diff --git a/Persistence.API/Program.cs b/Persistence.API/Program.cs index 51f3e13..93e62a1 100644 --- a/Persistence.API/Program.cs +++ b/Persistence.API/Program.cs @@ -1,11 +1,4 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Persistence.Repositories; -using Persistence.Repository; -using Persistence.Repository.Data; -using Persistence.Repository.Repositories; - namespace Persistence.API; public class Program @@ -13,7 +6,7 @@ public class Program public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); - Persistence.Repository.Startup.BeforeRunHandler(host); + Startup.BeforeRunHandler(host); host.Run(); } diff --git a/Persistence.API/Startup.cs b/Persistence.API/Startup.cs index d559627..1afaa18 100644 --- a/Persistence.API/Startup.cs +++ b/Persistence.API/Startup.cs @@ -1,4 +1,6 @@ using Persistence.Repository; +using Persistence.Database.Model; +using Persistence.Database.Postgres; namespace Persistence.API; @@ -18,8 +20,8 @@ public class Startup // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); - - services.AddInfrastructure(Configuration); + services.AddPersistenceDbContext(Configuration); + services.AddInfrastructure(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -37,4 +39,15 @@ public class Startup endpoints.MapControllers(); }); } + + public static void BeforeRunHandler(IHost host) + { + using var scope = host.Services.CreateScope(); + var provider = scope.ServiceProvider; + + var context = provider.GetRequiredService(); + context.Database.EnsureCreatedAndMigrated(); + } + + } diff --git a/Persistence.Database.Postgres/DependencyInjection.cs b/Persistence.Database.Postgres/DependencyInjection.cs new file mode 100644 index 0000000..1498932 --- /dev/null +++ b/Persistence.Database.Postgres/DependencyInjection.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Persistence.Database; +using Persistence.Database.Model; + +namespace Persistence.Database.Model; + +public static class DependencyInjection +{ + public static IServiceCollection AddPersistenceDbContext(this IServiceCollection services, IConfiguration configuration) + { + string connectionStringName = "DefaultConnection"; + + services.AddDbContext(options => + options.UseNpgsql(configuration.GetConnectionString(connectionStringName))); + + services.AddScoped(provider => provider.GetRequiredService()); + + return services; + } +} diff --git a/Persistence.Database/EFExtensionsInitialization.cs b/Persistence.Database.Postgres/EFExtensionsInitialization.cs similarity index 98% rename from Persistence.Database/EFExtensionsInitialization.cs rename to Persistence.Database.Postgres/EFExtensionsInitialization.cs index 3b28f61..3d2752f 100644 --- a/Persistence.Database/EFExtensionsInitialization.cs +++ b/Persistence.Database.Postgres/EFExtensionsInitialization.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Persistence.Database; +namespace Persistence.Database.Postgres; public static class EFExtensionsInitialization { public static void EnsureCreatedAndMigrated(this DatabaseFacade db) diff --git a/Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.Designer.cs b/Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.Designer.cs new file mode 100644 index 0000000..b66203a --- /dev/null +++ b/Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.Designer.cs @@ -0,0 +1,122 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Persistence.Database.Model; + +#nullable disable + +namespace Persistence.Database.Postgres.Migrations +{ + [DbContext(typeof(PersistenceDbContext))] + [Migration("20241115105149_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseCollation("Russian_Russia.1251") + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Persistence.Database.Model.DataSaub", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AxialLoad") + .HasColumnType("double precision") + .HasColumnName("axialLoad"); + + b.Property("BitDepth") + .HasColumnType("double precision") + .HasColumnName("bitDepth"); + + b.Property("BlockPosition") + .HasColumnType("double precision") + .HasColumnName("blockPosition"); + + b.Property("BlockSpeed") + .HasColumnType("double precision") + .HasColumnName("blockSpeed"); + + b.Property("Flow") + .HasColumnType("double precision") + .HasColumnName("flow"); + + b.Property("HookWeight") + .HasColumnType("double precision") + .HasColumnName("hookWeight"); + + b.Property("IdFeedRegulator") + .HasColumnType("integer") + .HasColumnName("idFeedRegulator"); + + b.Property("Mode") + .HasColumnType("integer") + .HasColumnName("mode"); + + b.Property("Mse") + .HasColumnType("double precision") + .HasColumnName("mse"); + + b.Property("MseState") + .HasColumnType("smallint") + .HasColumnName("mseState"); + + b.Property("Pressure") + .HasColumnType("double precision") + .HasColumnName("pressure"); + + b.Property("Pump0Flow") + .HasColumnType("double precision") + .HasColumnName("pump0Flow"); + + b.Property("Pump1Flow") + .HasColumnType("double precision") + .HasColumnName("pump1Flow"); + + b.Property("Pump2Flow") + .HasColumnType("double precision") + .HasColumnName("pump2Flow"); + + b.Property("RotorSpeed") + .HasColumnType("double precision") + .HasColumnName("rotorSpeed"); + + b.Property("RotorTorque") + .HasColumnType("double precision") + .HasColumnName("rotorTorque"); + + b.Property("TimeStamp") + .HasColumnType("integer") + .HasColumnName("timestamp"); + + b.Property("User") + .HasColumnType("text") + .HasColumnName("user"); + + b.Property("WellDepth") + .HasColumnType("double precision") + .HasColumnName("wellDepth"); + + b.HasKey("Id"); + + b.ToTable("DataSaub"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.cs b/Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.cs new file mode 100644 index 0000000..69839cd --- /dev/null +++ b/Persistence.Database.Postgres/Migrations/20241115105149_InitialCreate.cs @@ -0,0 +1,56 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Persistence.Database.Postgres.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("Npgsql:PostgresExtension:adminpack", ",,"); + + migrationBuilder.CreateTable( + name: "DataSaub", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + timestamp = table.Column(type: "integer", nullable: false), + mode = table.Column(type: "integer", nullable: true), + user = table.Column(type: "text", nullable: true), + wellDepth = table.Column(type: "double precision", nullable: true), + bitDepth = table.Column(type: "double precision", nullable: true), + blockPosition = table.Column(type: "double precision", nullable: true), + blockSpeed = table.Column(type: "double precision", nullable: true), + pressure = table.Column(type: "double precision", nullable: true), + axialLoad = table.Column(type: "double precision", nullable: true), + hookWeight = table.Column(type: "double precision", nullable: true), + rotorTorque = table.Column(type: "double precision", nullable: true), + rotorSpeed = table.Column(type: "double precision", nullable: true), + flow = table.Column(type: "double precision", nullable: true), + mseState = table.Column(type: "smallint", nullable: false), + idFeedRegulator = table.Column(type: "integer", nullable: false), + mse = table.Column(type: "double precision", nullable: true), + pump0Flow = table.Column(type: "double precision", nullable: true), + pump1Flow = table.Column(type: "double precision", nullable: true), + pump2Flow = table.Column(type: "double precision", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_DataSaub", x => x.id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DataSaub"); + } + } +} diff --git a/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs b/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs new file mode 100644 index 0000000..4483f7e --- /dev/null +++ b/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs @@ -0,0 +1,119 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Persistence.Database.Model; + +#nullable disable + +namespace Persistence.Database.Postgres.Migrations +{ + [DbContext(typeof(PersistenceDbContext))] + partial class PersistenceDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseCollation("Russian_Russia.1251") + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Persistence.Database.Model.DataSaub", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AxialLoad") + .HasColumnType("double precision") + .HasColumnName("axialLoad"); + + b.Property("BitDepth") + .HasColumnType("double precision") + .HasColumnName("bitDepth"); + + b.Property("BlockPosition") + .HasColumnType("double precision") + .HasColumnName("blockPosition"); + + b.Property("BlockSpeed") + .HasColumnType("double precision") + .HasColumnName("blockSpeed"); + + b.Property("Flow") + .HasColumnType("double precision") + .HasColumnName("flow"); + + b.Property("HookWeight") + .HasColumnType("double precision") + .HasColumnName("hookWeight"); + + b.Property("IdFeedRegulator") + .HasColumnType("integer") + .HasColumnName("idFeedRegulator"); + + b.Property("Mode") + .HasColumnType("integer") + .HasColumnName("mode"); + + b.Property("Mse") + .HasColumnType("double precision") + .HasColumnName("mse"); + + b.Property("MseState") + .HasColumnType("smallint") + .HasColumnName("mseState"); + + b.Property("Pressure") + .HasColumnType("double precision") + .HasColumnName("pressure"); + + b.Property("Pump0Flow") + .HasColumnType("double precision") + .HasColumnName("pump0Flow"); + + b.Property("Pump1Flow") + .HasColumnType("double precision") + .HasColumnName("pump1Flow"); + + b.Property("Pump2Flow") + .HasColumnType("double precision") + .HasColumnName("pump2Flow"); + + b.Property("RotorSpeed") + .HasColumnType("double precision") + .HasColumnName("rotorSpeed"); + + b.Property("RotorTorque") + .HasColumnType("double precision") + .HasColumnName("rotorTorque"); + + b.Property("TimeStamp") + .HasColumnType("integer") + .HasColumnName("timestamp"); + + b.Property("User") + .HasColumnType("text") + .HasColumnName("user"); + + b.Property("WellDepth") + .HasColumnType("double precision") + .HasColumnName("wellDepth"); + + b.HasKey("Id"); + + b.ToTable("DataSaub"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Persistence.Database.Postgres/Persistence.Database.Postgres.csproj b/Persistence.Database.Postgres/Persistence.Database.Postgres.csproj new file mode 100644 index 0000000..6b7cc14 --- /dev/null +++ b/Persistence.Database.Postgres/Persistence.Database.Postgres.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Persistence.Database/Model/PersistenceDbContext.cs b/Persistence.Database.Postgres/PersistenceDbContext.cs similarity index 71% rename from Persistence.Database/Model/PersistenceDbContext.cs rename to Persistence.Database.Postgres/PersistenceDbContext.cs index 3baf334..e4ec60f 100644 --- a/Persistence.Database/Model/PersistenceDbContext.cs +++ b/Persistence.Database.Postgres/PersistenceDbContext.cs @@ -1,19 +1,33 @@ using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Diagnostics.Metrics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; +using System.Data.Common; namespace Persistence.Database.Model; public partial class PersistenceDbContext : DbContext, IPersistenceDbContext { + private readonly DbConnection connection = null!; public DbSet DataSaub => Set(); - public PersistenceDbContext(DbContextOptions options) + + public PersistenceDbContext() + : base() { + + } + + public PersistenceDbContext(DbContextOptions options) + : base(options) + { + + } + + public PersistenceDbContext(DbConnection connection) + { + this.connection = connection; + } + + protected virtual DbConnection GetConnection() + { + return connection; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) @@ -30,5 +44,5 @@ public partial class PersistenceDbContext : DbContext, IPersistenceDbContext .HasAnnotation("Relational:Collation", "Russian_Russia.1251"); } - + } diff --git a/Persistence.Database.Postgres/Readme.md b/Persistence.Database.Postgres/Readme.md new file mode 100644 index 0000000..756a8f5 --- /dev/null +++ b/Persistence.Database.Postgres/Readme.md @@ -0,0 +1,5 @@ +## Создать миграцию +``` +dotnet ef migrations add --project Persistence.Database.Postgres + +``` \ No newline at end of file diff --git a/Persistence.Database/Model/DataSaub.cs b/Persistence.Database/Entity/DataSaub.cs similarity index 100% rename from Persistence.Database/Model/DataSaub.cs rename to Persistence.Database/Entity/DataSaub.cs diff --git a/Persistence.Database/Model/ITimestampedData.cs b/Persistence.Database/Entity/ITimestampedData.cs similarity index 100% rename from Persistence.Database/Model/ITimestampedData.cs rename to Persistence.Database/Entity/ITimestampedData.cs diff --git a/Persistence.Database/IPersistenceDbContext.cs b/Persistence.Database/IPersistenceDbContext.cs new file mode 100644 index 0000000..66f34ff --- /dev/null +++ b/Persistence.Database/IPersistenceDbContext.cs @@ -0,0 +1,8 @@ +using Microsoft.EntityFrameworkCore; +using Persistence.Database.Model; + +namespace Persistence.Database; +public interface IPersistenceDbContext : IDisposable +{ + DbSet DataSaub { get; } +} diff --git a/Persistence.Database/Model/IDbContextManager.cs b/Persistence.Database/Model/IDbContextManager.cs deleted file mode 100644 index a0a6491..0000000 --- a/Persistence.Database/Model/IDbContextManager.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Persistence.Database.Model; -public interface IDbContextManager -{ - //IConnectionManager ConnectionManager { get; } - - DbContext GetReadonlyDbContext(); - - DbContext GetDbContext(); - - DbContext CreateAndInitializeNewContext(); - - DbContext CreateAndInitializeNewContext(DbConnection connection); -} diff --git a/Persistence.Database/Model/IPersistenceDbContext.cs b/Persistence.Database/Model/IPersistenceDbContext.cs deleted file mode 100644 index af837d6..0000000 --- a/Persistence.Database/Model/IPersistenceDbContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using System; -using System.Collections.Generic; -using System.Diagnostics.Metrics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Persistence.Database.Model; -public interface IPersistenceDbContext : IDisposable -{ - DbSet DataSaub { get; } - DatabaseFacade Database { get; } - Task SaveChangesAsync(CancellationToken cancellationToken); -} diff --git a/Persistence.Database/Persistence.Database.csproj b/Persistence.Database/Persistence.Database.csproj index 4dca930..8154daf 100644 --- a/Persistence.Database/Persistence.Database.csproj +++ b/Persistence.Database/Persistence.Database.csproj @@ -7,11 +7,11 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/Persistence.Repository/DependencyInjection.cs b/Persistence.Repository/DependencyInjection.cs index 17904c8..21aa538 100644 --- a/Persistence.Repository/DependencyInjection.cs +++ b/Persistence.Repository/DependencyInjection.cs @@ -5,6 +5,7 @@ using Persistence.Repositories; using Persistence.Database.Model; using Persistence.Repository.Data; using Persistence.Repository.Repositories; +using Persistence.Database; namespace Persistence.Repository; public static class DependencyInjection @@ -12,17 +13,11 @@ public static class DependencyInjection public static void MapsterSetup() { } - public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) + + public static IServiceCollection AddInfrastructure(this IServiceCollection services) { MapsterSetup(); - string connectionStringName = "DefaultConnection"; - - services.AddDbContext(options => - options.UseNpgsql(configuration.GetConnectionString(connectionStringName))); - - services.AddScoped(provider => provider.GetRequiredService()); - services.AddTransient, TimeSeriesDataRepository>(); return services; diff --git a/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs b/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs index 97dd358..252888c 100644 --- a/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs +++ b/Persistence.Repository/Repositories/TimeSeriesDataRepository.cs @@ -4,9 +4,10 @@ using Persistence.Models; using Persistence.Repositories; using Persistence.Database.Model; using Persistence.Repository.Data; +using Persistence.Database; namespace Persistence.Repository.Repositories; -public abstract class TimeSeriesDataRepository : ITimeSeriesDataRepository +public class TimeSeriesDataRepository : ITimeSeriesDataRepository where TEntity : class where TDto : class, ITimeSeriesAbstractDto, new() { @@ -17,7 +18,7 @@ public abstract class TimeSeriesDataRepository : ITimeSeriesDataR this.db = db; } - protected virtual IQueryable GetQueryReadOnly() => db.Set(); + protected virtual IQueryable GetQueryReadOnly() => this.db.Set(); public async Task> GetAsync(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) { diff --git a/Persistence.Repository/Startup.cs b/Persistence.Repository/Startup.cs deleted file mode 100644 index 1d57cbb..0000000 --- a/Persistence.Repository/Startup.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Persistence.Database; -using Persistence.Database.Model; - -namespace Persistence.Repository; -public class Startup -{ - public static void BeforeRunHandler(IHost host) - { - using var scope = host.Services.CreateScope(); - var provider = scope.ServiceProvider; - - var context = provider.GetRequiredService(); - context.Database.EnsureCreatedAndMigrated(); - - } -} diff --git a/Persistence.sln b/Persistence.sln index a3e9f69..ce44190 100644 --- a/Persistence.sln +++ b/Persistence.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence.Repository", "P EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence.Database", "Persistence.Database\Persistence.Database.csproj", "{F77475D1-D074-407A-9D69-2FADDDAE2056}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence.IntegrationTests", "Persistence.IntegrationTests\Persistence.IntegrationTests.csproj", "{10752C25-3773-4081-A1F2-215A1D950126}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence.IntegrationTests", "Persistence.IntegrationTests\Persistence.IntegrationTests.csproj", "{10752C25-3773-4081-A1F2-215A1D950126}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence.Database.Postgres", "Persistence.Database.Postgres\Persistence.Database.Postgres.csproj", "{CC284D27-162D-490C-B6CF-74D666B7C5F3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {10752C25-3773-4081-A1F2-215A1D950126}.Debug|Any CPU.Build.0 = Debug|Any CPU {10752C25-3773-4081-A1F2-215A1D950126}.Release|Any CPU.ActiveCfg = Release|Any CPU {10752C25-3773-4081-A1F2-215A1D950126}.Release|Any CPU.Build.0 = Release|Any CPU + {CC284D27-162D-490C-B6CF-74D666B7C5F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC284D27-162D-490C-B6CF-74D666B7C5F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC284D27-162D-490C-B6CF-74D666B7C5F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC284D27-162D-490C-B6CF-74D666B7C5F3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE