From e4412d3b2a26f29e0d30eb44b7d22b892ca64d3b Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Fri, 31 Mar 2023 11:10:16 +0500 Subject: [PATCH] reviw db model and migration --- ...ITS_GTR_and_manual_hypertable.Designer.cs} | 15 +++++----- ...d_table_WITS_GTR_and_manual_hypertable.cs} | 11 ++----- .../AsbCloudDbContextModelSnapshot.cs | 13 ++++---- AsbCloudDb/Model/AsbCloudDbContext.cs | 12 ++++---- AsbCloudDb/Model/GTR/IWitsBase.cs | 8 ----- AsbCloudDb/Model/GTR/WitsFloat.cs | 22 +------------- AsbCloudDb/Model/GTR/WitsInt.cs | 22 +------------- AsbCloudDb/Model/GTR/WitsItemBase.cs | 30 +++++++++++++++++++ AsbCloudDb/Model/GTR/WitsStr.cs | 24 +-------------- .../Controllers/GTR/GtrWitsController.cs | 11 +++++++ 10 files changed, 66 insertions(+), 102 deletions(-) rename AsbCloudDb/Migrations/{20230328185054_add_table_WITS_GTR_and_manual_hypertable.Designer.cs => 20230331060526_add_table_WITS_GTR_and_manual_hypertable.Designer.cs} (99%) rename AsbCloudDb/Migrations/{20230328185054_add_table_WITS_GTR_and_manual_hypertable.cs => 20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs} (85%) delete mode 100644 AsbCloudDb/Model/GTR/IWitsBase.cs create mode 100644 AsbCloudDb/Model/GTR/WitsItemBase.cs create mode 100644 AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs diff --git a/AsbCloudDb/Migrations/20230328185054_add_table_WITS_GTR_and_manual_hypertable.Designer.cs b/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.Designer.cs similarity index 99% rename from AsbCloudDb/Migrations/20230328185054_add_table_WITS_GTR_and_manual_hypertable.Designer.cs rename to AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.Designer.cs index a64b21f7..0fd8b600 100644 --- a/AsbCloudDb/Migrations/20230328185054_add_table_WITS_GTR_and_manual_hypertable.Designer.cs +++ b/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.Designer.cs @@ -13,7 +13,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AsbCloudDb.Migrations { [DbContext(typeof(AsbCloudDbContext))] - [Migration("20230328185054_add_table_WITS_GTR_and_manual_hypertable")] + [Migration("20230331060526_add_table_WITS_GTR_and_manual_hypertable")] partial class add_table_WITS_GTR_and_manual_hypertable { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -821,9 +821,9 @@ namespace AsbCloudDb.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("date"); - b.Property("Value") + b.Property("Value") .HasColumnType("real") - .HasColumnName("value"); + .HasColumnName("Value"); b.HasKey("IdTelemetry", "IdRecord", "IdItem"); @@ -850,8 +850,8 @@ namespace AsbCloudDb.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("date"); - b.Property("Value") - .HasColumnType("bigint") + b.Property("Value") + .HasColumnType("integer") .HasColumnName("Value"); b.HasKey("IdTelemetry", "IdRecord", "IdItem"); @@ -880,9 +880,8 @@ namespace AsbCloudDb.Migrations .HasColumnName("date"); b.Property("Value") - .HasMaxLength(64) - .HasColumnType("character varying(64)") - .HasColumnName("value"); + .HasColumnType("text") + .HasColumnName("Value"); b.HasKey("IdTelemetry", "IdRecord", "IdItem"); diff --git a/AsbCloudDb/Migrations/20230328185054_add_table_WITS_GTR_and_manual_hypertable.cs b/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs similarity index 85% rename from AsbCloudDb/Migrations/20230328185054_add_table_WITS_GTR_and_manual_hypertable.cs rename to AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs index 3d1e3cca..f542d6d7 100644 --- a/AsbCloudDb/Migrations/20230328185054_add_table_WITS_GTR_and_manual_hypertable.cs +++ b/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs @@ -17,7 +17,7 @@ namespace AsbCloudDb.Migrations id_record = table.Column(type: "integer", nullable: false), id_item = table.Column(type: "integer", nullable: false), date = table.Column(type: "timestamp with time zone", nullable: false), - value = table.Column(type: "real", nullable: true) + Value = table.Column(type: "real", nullable: false) }, constraints: table => { @@ -39,7 +39,7 @@ namespace AsbCloudDb.Migrations id_record = table.Column(type: "integer", nullable: false), id_item = table.Column(type: "integer", nullable: false), date = table.Column(type: "timestamp with time zone", nullable: false), - Value = table.Column(type: "bigint", nullable: true) + Value = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -61,7 +61,7 @@ namespace AsbCloudDb.Migrations id_record = table.Column(type: "integer", nullable: false), id_item = table.Column(type: "integer", nullable: false), date = table.Column(type: "timestamp with time zone", nullable: false), - value = table.Column(type: "character varying(64)", maxLength: 64, nullable: true) + Value = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -74,11 +74,6 @@ namespace AsbCloudDb.Migrations onDelete: ReferentialAction.Cascade); }, comment: "таблица данных ГТИ с типом значения string"); - - migrationBuilder.Sql - ("SELECT create_hypertable('t_wits_string','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); " + - "SELECT create_hypertable('t_wits_float','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); " + - "SELECT create_hypertable('t_wits_int','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); "); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs index 0b56ca6e..d1538c9c 100644 --- a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs +++ b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs @@ -819,9 +819,9 @@ namespace AsbCloudDb.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("date"); - b.Property("Value") + b.Property("Value") .HasColumnType("real") - .HasColumnName("value"); + .HasColumnName("Value"); b.HasKey("IdTelemetry", "IdRecord", "IdItem"); @@ -848,8 +848,8 @@ namespace AsbCloudDb.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("date"); - b.Property("Value") - .HasColumnType("bigint") + b.Property("Value") + .HasColumnType("integer") .HasColumnName("Value"); b.HasKey("IdTelemetry", "IdRecord", "IdItem"); @@ -878,9 +878,8 @@ namespace AsbCloudDb.Migrations .HasColumnName("date"); b.Property("Value") - .HasMaxLength(64) - .HasColumnType("character varying(64)") - .HasColumnName("value"); + .HasColumnType("text") + .HasColumnName("Value"); b.HasKey("IdTelemetry", "IdRecord", "IdItem"); diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 2d02a2fe..d749ceb7 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -344,22 +344,22 @@ namespace AsbCloudDb.Model { entity.HasKey( nameof(ITelemetryData.IdTelemetry), - nameof(IWitsBase.IdRecord), - nameof(IWitsBase.IdItem)); + nameof(WitsItemBase.IdRecord), + nameof(WitsItemBase.IdItem)); }); modelBuilder.Entity(entity => { entity.HasKey( nameof(ITelemetryData.IdTelemetry), - nameof(IWitsBase.IdRecord), - nameof(IWitsBase.IdItem)); + nameof(WitsItemBase.IdRecord), + nameof(WitsItemBase.IdItem)); }); modelBuilder.Entity(entity => { entity.HasKey( nameof(ITelemetryData.IdTelemetry), - nameof(IWitsBase.IdRecord), - nameof(IWitsBase.IdItem)); + nameof(WitsItemBase.IdRecord), + nameof(WitsItemBase.IdItem)); }); diff --git a/AsbCloudDb/Model/GTR/IWitsBase.cs b/AsbCloudDb/Model/GTR/IWitsBase.cs deleted file mode 100644 index 28651269..00000000 --- a/AsbCloudDb/Model/GTR/IWitsBase.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace AsbCloudDb.Model.GTR -{ - public interface IWitsBase:ITelemetryData - { - public int IdRecord { get; set; } - public int IdItem { get; set; } - } -} \ No newline at end of file diff --git a/AsbCloudDb/Model/GTR/WitsFloat.cs b/AsbCloudDb/Model/GTR/WitsFloat.cs index 84156a2a..e993b6f6 100644 --- a/AsbCloudDb/Model/GTR/WitsFloat.cs +++ b/AsbCloudDb/Model/GTR/WitsFloat.cs @@ -1,27 +1,7 @@ using Microsoft.EntityFrameworkCore; -using System; using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model.GTR { [Table("t_wits_float"), Comment("таблица данных ГТИ с типом значения float")] - public class WitsFloat : IWitsBase - { - [Column("id_telemetry")] - public int IdTelemetry { get; set; } - - [Column("id_record")] - public int IdRecord { get; set; } - - [Column("id_item")] - public int IdItem { get; set; } - - [Column("date", TypeName = "timestamp with time zone")] - public DateTimeOffset DateTime { get; set; } - - [Column("value")] - public float? Value { get; set; } - - [ForeignKey(nameof(IdTelemetry))] - public virtual Telemetry? Telemetry { get; set; } - } + public class WitsFloat : WitsItemBase { } } diff --git a/AsbCloudDb/Model/GTR/WitsInt.cs b/AsbCloudDb/Model/GTR/WitsInt.cs index d70378ae..22922688 100644 --- a/AsbCloudDb/Model/GTR/WitsInt.cs +++ b/AsbCloudDb/Model/GTR/WitsInt.cs @@ -1,28 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System; using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model.GTR { [Table("t_wits_int"), Comment("таблица данных ГТИ с типом значения int16 int32")] - public class WitsInt : IWitsBase - { - [Column("id_telemetry")] - public int IdTelemetry { get; set; } - - [Column("id_record")] - public int IdRecord { get; set; } - - [Column("id_item")] - public int IdItem { get; set; } - - [Column("date", TypeName = "timestamp with time zone")] - public DateTimeOffset DateTime { get; set; } - - [Column("Value", TypeName = "bigint")] - public int? Value { get; set; } - - [ForeignKey(nameof(IdTelemetry))] - public virtual Telemetry? Telemetry { get; set; } - } + public class WitsInt : WitsItemBase, ITelemetryData { } } diff --git a/AsbCloudDb/Model/GTR/WitsItemBase.cs b/AsbCloudDb/Model/GTR/WitsItemBase.cs new file mode 100644 index 00000000..0127997d --- /dev/null +++ b/AsbCloudDb/Model/GTR/WitsItemBase.cs @@ -0,0 +1,30 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AsbCloudDb.Model.GTR +{ + public class WitsItemBase : ITelemetryData + { + [Column("id_telemetry")] + public int IdTelemetry { get; set; } + + [Column("id_record")] + public int IdRecord { get; set; } + + [Column("id_item")] + public int IdItem { get; set; } + + [Column("date", TypeName = "timestamp with time zone")] + public DateTimeOffset DateTime { get; set; } + + [Column("Value")] + public T? Value { get; set; } + + [ForeignKey(nameof(IdTelemetry))] + public virtual Telemetry? Telemetry { get; set; } + } + + public class WitsItemString : WitsItemBase { } + public class WitsItemFloat : WitsItemBase { } + public class WitsItemInt : WitsItemBase { } +} diff --git a/AsbCloudDb/Model/GTR/WitsStr.cs b/AsbCloudDb/Model/GTR/WitsStr.cs index 13e0ca81..97ff2dc9 100644 --- a/AsbCloudDb/Model/GTR/WitsStr.cs +++ b/AsbCloudDb/Model/GTR/WitsStr.cs @@ -1,30 +1,8 @@ using Microsoft.EntityFrameworkCore; -using System; -using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model.GTR { [Table("t_wits_string"), Comment("таблица данных ГТИ с типом значения string")] - public class WitsStr: IWitsBase - { - [Column("id_telemetry")] - public int IdTelemetry { get; set; } - - [Column("id_record")] - public int IdRecord { get; set; } - - [Column("id_item")] - public int IdItem { get; set; } - - [Column("date", TypeName = "timestamp with time zone")] - public DateTimeOffset DateTime { get; set; } - - [Column("value")] - [StringLength(64)] - public string? Value { get; set; } - - [ForeignKey(nameof(IdTelemetry))] - public virtual Telemetry? Telemetry { get; set; } - } + public class WitsStr: WitsItemBase { } } diff --git a/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs b/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs new file mode 100644 index 00000000..5d6f69cc --- /dev/null +++ b/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace AsbCloudWebApi.Controllers.GTR +{ + [Route("api/[controller]")] + [ApiController] + public class GtrWitsController : ControllerBase + { + } +}