From 381557459b86d7e14fff9d6f699924612f64273e Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 25 Nov 2024 10:05:23 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B5=D0=BD=D0=B4=D0=B6=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=20(=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20241122124437_AddChangeLog.Designer.cs | 152 ++++++++++++++++++ .../Migrations/20241122124437_AddChangeLog.cs | 39 +++++ .../PersistenceDbContextModelSnapshot.cs | 37 +++++ .../PersistenceDbContext.cs | 1 + .../Entity/ChangeLogAbstractData.cs | 53 ++++++ .../Entity/IChangeLogAbstractData.cs | 43 +++++ Persistence.Database/IPersistenceDbContext.cs | 1 + Persistence/Models/ChangeLogDto.cs | 29 ++-- ...ogAbstract.cs => IChangeLogAbstractDto.cs} | 30 +--- 9 files changed, 349 insertions(+), 36 deletions(-) create mode 100644 Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs create mode 100644 Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs create mode 100644 Persistence.Database/Entity/ChangeLogAbstractData.cs create mode 100644 Persistence.Database/Entity/IChangeLogAbstractData.cs rename Persistence/Models/{IChangeLogAbstract.cs => IChangeLogAbstractDto.cs} (53%) diff --git a/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs b/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs new file mode 100644 index 0000000..df89efd --- /dev/null +++ b/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs @@ -0,0 +1,152 @@ +// +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("20241122124437_AddChangeLog")] + partial class AddChangeLog + { + /// + 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.ChangeLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Creation") + .HasColumnType("timestamp with time zone") + .HasColumnName("Creation"); + + b.Property("IdAuthor") + .HasColumnType("integer") + .HasColumnName("IdAuthor"); + + b.Property("IdEditor") + .HasColumnType("integer") + .HasColumnName("IdEditor"); + + b.Property("IdNext") + .HasColumnType("integer") + .HasColumnName("IdNext"); + + b.Property("Obsolete") + .HasColumnType("timestamp with time zone") + .HasColumnName("Obsolete"); + + b.Property("Value") + .IsRequired() + .HasColumnType("jsonb") + .HasColumnName("Value"); + + b.HasKey("Id"); + + b.ToTable("ChangeLog"); + }); + + modelBuilder.Entity("Persistence.Database.Model.DataSaub", b => + { + b.Property("Date") + .HasColumnType("timestamp with time zone") + .HasColumnName("date"); + + 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("User") + .HasColumnType("text") + .HasColumnName("user"); + + b.Property("WellDepth") + .HasColumnType("double precision") + .HasColumnName("wellDepth"); + + b.HasKey("Date"); + + b.ToTable("DataSaub"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs b/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs new file mode 100644 index 0000000..70aad1d --- /dev/null +++ b/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Persistence.Database.Postgres.Migrations +{ + /// + public partial class AddChangeLog : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ChangeLog", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + IdAuthor = table.Column(type: "integer", nullable: false), + IdEditor = table.Column(type: "integer", nullable: true), + Creation = table.Column(type: "timestamp with time zone", nullable: false), + Obsolete = table.Column(type: "timestamp with time zone", nullable: true), + IdNext = table.Column(type: "integer", nullable: true), + Value = table.Column(type: "jsonb", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChangeLog", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ChangeLog"); + } + } +} diff --git a/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs b/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs index 394c112..99dab9a 100644 --- a/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs +++ b/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs @@ -24,6 +24,43 @@ namespace Persistence.Database.Postgres.Migrations NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack"); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("Persistence.Database.Model.ChangeLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Creation") + .HasColumnType("timestamp with time zone") + .HasColumnName("Creation"); + + b.Property("IdAuthor") + .HasColumnType("integer") + .HasColumnName("IdAuthor"); + + b.Property("IdEditor") + .HasColumnType("integer") + .HasColumnName("IdEditor"); + + b.Property("IdNext") + .HasColumnType("integer") + .HasColumnName("IdNext"); + + b.Property("Obsolete") + .HasColumnType("timestamp with time zone") + .HasColumnName("Obsolete"); + + b.Property("Value") + .IsRequired() + .HasColumnType("jsonb") + .HasColumnName("Value"); + + b.HasKey("Id"); + + b.ToTable("ChangeLog"); + }); + modelBuilder.Entity("Persistence.Database.Model.DataSaub", b => { b.Property("Date") diff --git a/Persistence.Database.Postgres/PersistenceDbContext.cs b/Persistence.Database.Postgres/PersistenceDbContext.cs index f68be73..097d3f3 100644 --- a/Persistence.Database.Postgres/PersistenceDbContext.cs +++ b/Persistence.Database.Postgres/PersistenceDbContext.cs @@ -5,6 +5,7 @@ namespace Persistence.Database.Model; public partial class PersistenceDbContext : DbContext, IPersistenceDbContext { public DbSet DataSaub => Set(); + public DbSet ChangeLog => Set(); public PersistenceDbContext() : base() diff --git a/Persistence.Database/Entity/ChangeLogAbstractData.cs b/Persistence.Database/Entity/ChangeLogAbstractData.cs new file mode 100644 index 0000000..ffc19c9 --- /dev/null +++ b/Persistence.Database/Entity/ChangeLogAbstractData.cs @@ -0,0 +1,53 @@ + +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace Persistence.Database.Model; + +/// +/// Часть записи описывающая изменение +/// +public class ChangeLog : IChangeLogAbstractData +{ + /// + /// Ид записи + /// + [Key, Column("Id")] + public Guid Id { get; set; } + + /// + /// Автор изменения + /// + [Column("IdAuthor")] + public Guid IdAuthor { get; set; } + + /// + /// Редактор + /// + [Column("IdEditor")] + public Guid? IdEditor { get; set; } + + /// + /// Дата создания записи + /// + [Column("Creation")] + public DateTimeOffset Creation { get; set; } + + /// + /// Дата устаревания (например при удалении) + /// + [Column("Obsolete")] + public DateTimeOffset? Obsolete { get; set; } + + /// + /// Id заменяющей записи + /// + [Column("IdNext")] + public Guid? IdNext { get; set; } + + /// + /// Значение + /// + [Column("Value", TypeName = "jsonb")] + public required object Value { get; set; } +} diff --git a/Persistence.Database/Entity/IChangeLogAbstractData.cs b/Persistence.Database/Entity/IChangeLogAbstractData.cs new file mode 100644 index 0000000..750fef4 --- /dev/null +++ b/Persistence.Database/Entity/IChangeLogAbstractData.cs @@ -0,0 +1,43 @@ + +namespace Persistence.Database.Model; + +/// +/// Часть записи описывающая изменение +/// +public interface IChangeLogAbstractData +{ + /// + /// Ид записи + /// + public Guid Id { get; set; } + + /// + /// Автор изменения + /// + public int IdAuthor { get; set; } + + /// + /// Редактор + /// + public int? IdEditor { get; set; } + + /// + /// Дата создания записи + /// + public DateTimeOffset Creation { get; set; } + + /// + /// Дата устаревания (например при удалении) + /// + public DateTimeOffset? Obsolete { get; set; } + + /// + /// Id заменяющей записи + /// + public int? IdNext { get; set; } + + /// + /// Значение + /// + public object Value { get; set; } +} diff --git a/Persistence.Database/IPersistenceDbContext.cs b/Persistence.Database/IPersistenceDbContext.cs index 66f34ff..0837294 100644 --- a/Persistence.Database/IPersistenceDbContext.cs +++ b/Persistence.Database/IPersistenceDbContext.cs @@ -5,4 +5,5 @@ namespace Persistence.Database; public interface IPersistenceDbContext : IDisposable { DbSet DataSaub { get; } + DbSet ChangeLog { get; } } diff --git a/Persistence/Models/ChangeLogDto.cs b/Persistence/Models/ChangeLogDto.cs index 6b2a090..d9acc66 100644 --- a/Persistence/Models/ChangeLogDto.cs +++ b/Persistence/Models/ChangeLogDto.cs @@ -1,9 +1,11 @@ + namespace Persistence.Models; /// /// Часть записи описывающая изменение /// -public class ChangeLogDto where T: class +public class ChangeLogDto : IChangeLogAbstractDto + where T: class { /// /// Запись @@ -11,32 +13,37 @@ public class ChangeLogDto where T: class public required T Item { get; set; } /// - /// Автор + /// /// - public UserDto? Author { get; set; } + public int Id { get; set; } /// - /// Автор + /// /// - public UserDto? Editor { get; set; } + public int IdAuthor { get; set; } /// - /// Дата создания записи + /// + /// + public int? IdEditor { get; set; } + + /// + /// /// public DateTimeOffset Creation { get; set; } /// - /// Дата устаревания (например, при удалении) + /// /// public DateTimeOffset? Obsolete { get; set; } /// - /// Id состояния + /// /// - public int IdState { get; set; } + public int? IdNext { get; set; } /// - /// Id заменяемой записи + /// /// - public int? IdPrevious { get; set; } + public required object Value { get; set; } } diff --git a/Persistence/Models/IChangeLogAbstract.cs b/Persistence/Models/IChangeLogAbstractDto.cs similarity index 53% rename from Persistence/Models/IChangeLogAbstract.cs rename to Persistence/Models/IChangeLogAbstractDto.cs index a23ab1b..b9fd209 100644 --- a/Persistence/Models/IChangeLogAbstract.cs +++ b/Persistence/Models/IChangeLogAbstractDto.cs @@ -3,28 +3,8 @@ /// /// Часть записи описывающая изменение /// -public interface IChangeLogAbstract +public interface IChangeLogAbstractDto { - /// - /// Актуальная - /// - public const int IdStateActual = 0; - - /// - /// Замененная - /// - public const int IdStateReplaced = 1; - - /// - /// Удаленная - /// - public const int IdStateDeleted = 2; - - /// - /// Очищено при импорте - /// - public const int IdCleared = 3; - /// /// Ид записи /// @@ -51,12 +31,12 @@ public interface IChangeLogAbstract public DateTimeOffset? Obsolete { get; set; } /// - /// "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная + /// Id заменяющей записи /// - public int IdState { get; set; } + public int? IdNext { get; set; } /// - /// Id заменяемой записи + /// Значение /// - public int? IdPrevious { get; set; } + public object Value { get; set; } }