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/20241118052225_SetpointMigration.Designer.cs b/Persistence.Database.Postgres/Migrations/20241118052225_SetpointMigration.Designer.cs
new file mode 100644
index 0000000..9399dd4
--- /dev/null
+++ b/Persistence.Database.Postgres/Migrations/20241118052225_SetpointMigration.Designer.cs
@@ -0,0 +1,146 @@
+//
+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("20241118052225_SetpointMigration")]
+ partial class SetpointMigration
+ {
+ ///
+ 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");
+ });
+
+ modelBuilder.Entity("Persistence.Database.Model.Setpoint", b =>
+ {
+ b.Property("Key")
+ .HasColumnType("uuid")
+ .HasComment("Ключ");
+
+ b.Property("Created")
+ .HasColumnType("timestamp with time zone")
+ .HasComment("Дата изменения уставки");
+
+ b.Property("IdUser")
+ .HasColumnType("integer")
+ .HasComment("Id автора последнего изменения");
+
+ b.Property