reviw db model and migration

This commit is contained in:
eugeniy_ivanov 2023-03-31 11:10:16 +05:00
parent 301f1c8013
commit e4412d3b2a
10 changed files with 66 additions and 102 deletions

View File

@ -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<float?>("Value")
b.Property<float>("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<long?>("Value")
.HasColumnType("bigint")
b.Property<int>("Value")
.HasColumnType("integer")
.HasColumnName("Value");
b.HasKey("IdTelemetry", "IdRecord", "IdItem");
@ -880,9 +880,8 @@ namespace AsbCloudDb.Migrations
.HasColumnName("date");
b.Property<string>("Value")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("value");
.HasColumnType("text")
.HasColumnName("Value");
b.HasKey("IdTelemetry", "IdRecord", "IdItem");

View File

@ -17,7 +17,7 @@ namespace AsbCloudDb.Migrations
id_record = table.Column<int>(type: "integer", nullable: false),
id_item = table.Column<int>(type: "integer", nullable: false),
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
value = table.Column<float>(type: "real", nullable: true)
Value = table.Column<float>(type: "real", nullable: false)
},
constraints: table =>
{
@ -39,7 +39,7 @@ namespace AsbCloudDb.Migrations
id_record = table.Column<int>(type: "integer", nullable: false),
id_item = table.Column<int>(type: "integer", nullable: false),
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Value = table.Column<long>(type: "bigint", nullable: true)
Value = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
@ -61,7 +61,7 @@ namespace AsbCloudDb.Migrations
id_record = table.Column<int>(type: "integer", nullable: false),
id_item = table.Column<int>(type: "integer", nullable: false),
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
value = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
Value = table.Column<string>(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)

View File

@ -819,9 +819,9 @@ namespace AsbCloudDb.Migrations
.HasColumnType("timestamp with time zone")
.HasColumnName("date");
b.Property<float?>("Value")
b.Property<float>("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<long?>("Value")
.HasColumnType("bigint")
b.Property<int>("Value")
.HasColumnType("integer")
.HasColumnName("Value");
b.HasKey("IdTelemetry", "IdRecord", "IdItem");
@ -878,9 +878,8 @@ namespace AsbCloudDb.Migrations
.HasColumnName("date");
b.Property<string>("Value")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("value");
.HasColumnType("text")
.HasColumnName("Value");
b.HasKey("IdTelemetry", "IdRecord", "IdItem");

View File

@ -344,22 +344,22 @@ namespace AsbCloudDb.Model
{
entity.HasKey(
nameof(ITelemetryData.IdTelemetry),
nameof(IWitsBase.IdRecord),
nameof(IWitsBase.IdItem));
nameof(WitsItemBase<float>.IdRecord),
nameof(WitsItemBase<float>.IdItem));
});
modelBuilder.Entity<WitsInt>(entity =>
{
entity.HasKey(
nameof(ITelemetryData.IdTelemetry),
nameof(IWitsBase.IdRecord),
nameof(IWitsBase.IdItem));
nameof(WitsItemBase<int>.IdRecord),
nameof(WitsItemBase<int>.IdItem));
});
modelBuilder.Entity<WitsStr>(entity =>
{
entity.HasKey(
nameof(ITelemetryData.IdTelemetry),
nameof(IWitsBase.IdRecord),
nameof(IWitsBase.IdItem));
nameof(WitsItemBase<string>.IdRecord),
nameof(WitsItemBase<string>.IdItem));
});

View File

@ -1,8 +0,0 @@
namespace AsbCloudDb.Model.GTR
{
public interface IWitsBase:ITelemetryData
{
public int IdRecord { get; set; }
public int IdItem { get; set; }
}
}

View File

@ -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<float> { }
}

View File

@ -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<int>, ITelemetryData { }
}

View File

@ -0,0 +1,30 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model.GTR
{
public class WitsItemBase<T> : 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<string> { }
public class WitsItemFloat : WitsItemBase<float> { }
public class WitsItemInt : WitsItemBase<int> { }
}

View File

@ -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<string> { }
}

View File

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers.GTR
{
[Route("api/[controller]")]
[ApiController]
public class GtrWitsController : ControllerBase
{
}
}