Изменение модели данных

1. Изменён объект суточного отчёта
2. Поправлен DbContext
3. Добавлена новая миграция
This commit is contained in:
Степанов Дмитрий 2023-11-03 17:56:26 +05:00
parent 070cd185cb
commit 6dbed6c457
7 changed files with 9038 additions and 20 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,127 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Update_DailyReport : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "t_id_well_date_start_pk",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "start_date",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "info",
table: "t_daily_report");
migrationBuilder.AddColumn<int>(
name: "Id",
table: "t_daily_report",
type: "integer",
nullable: false,
defaultValue: 0)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddColumn<string>(
name: "blocks",
table: "t_daily_report",
type: "jsonb",
nullable: true,
comment: "Блоки использующиеся в отчёте");
migrationBuilder.AddColumn<DateTime>(
name: "date_end",
table: "t_daily_report",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
comment: "Конечная дата отчёта");
migrationBuilder.AddColumn<DateTime>(
name: "date_last_update",
table: "t_daily_report",
type: "timestamp with time zone",
nullable: true,
comment: "Дата последнего обновления");
migrationBuilder.AddColumn<DateTime>(
name: "date_start",
table: "t_daily_report",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
comment: "Начальная дата отчёта");
migrationBuilder.AddPrimaryKey(
name: "PK_t_daily_report",
table: "t_daily_report",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_t_daily_report_id_well_date_start",
table: "t_daily_report",
columns: new[] { "id_well", "date_start" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_t_daily_report",
table: "t_daily_report");
migrationBuilder.DropIndex(
name: "IX_t_daily_report_id_well_date_start",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "Id",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "blocks",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "date_end",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "date_last_update",
table: "t_daily_report");
migrationBuilder.DropColumn(
name: "date_start",
table: "t_daily_report");
migrationBuilder.AddColumn<DateOnly>(
name: "start_date",
table: "t_daily_report",
type: "date",
nullable: false,
defaultValue: new DateOnly(1, 1, 1),
comment: "Дата отчёта");
migrationBuilder.AddColumn<string>(
name: "info",
table: "t_daily_report",
type: "jsonb",
nullable: false,
defaultValue: "",
comment: "Список параметров для отчёта");
migrationBuilder.AddPrimaryKey(
name: "t_id_well_date_start_pk",
table: "t_daily_report",
columns: new[] { "id_well", "start_date" });
}
}
}

View File

@ -221,26 +221,43 @@ namespace AsbCloudDb.Migrations
b.HasComment("Контакты");
});
modelBuilder.Entity("AsbCloudDb.Model.DailyReport.DailyReport", b =>
modelBuilder.Entity("AsbCloudDb.Model.DailyReport", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Blocks")
.HasColumnType("jsonb")
.HasColumnName("blocks")
.HasComment("Блоки использующиеся в отчёте");
b.Property<DateTime>("DateEnd")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_end")
.HasComment("Конечная дата отчёта");
b.Property<DateTime?>("DateLastUpdate")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_last_update")
.HasComment("Дата последнего обновления");
b.Property<DateTime>("DateStart")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_start")
.HasComment("Начальная дата отчёта");
b.Property<int>("IdWell")
.HasColumnType("integer")
.HasColumnName("id_well")
.HasComment("ID скважины");
b.Property<DateOnly>("StartDate")
.HasColumnType("date")
.HasColumnName("start_date")
.HasComment("Дата отчёта");
b.HasKey("Id");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("info")
.HasComment("Список параметров для отчёта");
b.HasKey("IdWell", "StartDate")
.HasName("t_id_well_date_start_pk");
b.HasIndex("IdWell", "DateStart")
.IsUnique();
b.ToTable("t_daily_report");
@ -2372,6 +2389,12 @@ namespace AsbCloudDb.Migrations
Id = 528,
Description = "Разрешение на удаление контакта",
Name = "WellContact.delete"
},
new
{
Id = 529,
Description = "Разрешение на получение отчетов drill test",
Name = "DrillTestReport.get"
});
});
@ -4038,6 +4061,11 @@ namespace AsbCloudDb.Migrations
{
IdUserRole = 1,
IdPermission = 528
},
new
{
IdUserRole = 1,
IdPermission = 529
});
});
@ -7834,7 +7862,7 @@ namespace AsbCloudDb.Migrations
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.DailyReport.DailyReport", b =>
modelBuilder.Entity("AsbCloudDb.Model.DailyReport", b =>
{
b.HasOne("AsbCloudDb.Model.Well", "Well")
.WithMany()

View File

@ -13,7 +13,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<Cluster> Clusters => Set<Cluster>();
public virtual DbSet<Company> Companies => Set<Company>();
public virtual DbSet<CompanyType> CompaniesTypes => Set<CompanyType>();
public virtual DbSet<DailyReport.DailyReport> DailyReports => Set <DailyReport.DailyReport >();
public virtual DbSet<DailyReport> DailyReports => Set <DailyReport>();
public virtual DbSet<Deposit> Deposits => Set<Deposit>();
public virtual DbSet<DetectedOperation> DetectedOperations => Set<DetectedOperation>();
public virtual DbSet<PlannedTrajectory> PlannedTrajectories => Set<PlannedTrajectory>();
@ -331,11 +331,12 @@ namespace AsbCloudDb.Model
.IsRequired();
});
modelBuilder.Entity<DailyReport.DailyReport >(entity =>
modelBuilder.Entity<DailyReport>(entity =>
{
entity.HasKey(e => new { e.IdWell, e.StartDate })
.HasName("t_id_well_date_start_pk");
entity.Property(e => e.Info)
entity.HasIndex(e => new { e.IdWell, e.DateStart })
.IsUnique();
entity.Property(e => e.Blocks)
.HasJsonConversion();
});

View File

@ -0,0 +1,31 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudDb.Model;
[Table("t_daily_report"), Comment("Ежедневные отчёты")]
public class DailyReport : IId
{
[Key]
public int Id { get; set; }
[Column("id_well"), Comment("ID скважины")]
public int IdWell { get; set; }
[Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")]
public DateTime? DateLastUpdate { get; set; }
[Column("date_start", TypeName = "timestamp with time zone"), Comment("Начальная дата отчёта")]
public DateTime DateStart { get; set; }
[Column("date_end", TypeName = "timestamp with time zone"), Comment("Конечная дата отчёта")]
public DateTime DateEnd { get; set; }
[Column("blocks", TypeName = "jsonb"), Comment("Блоки использующиеся в отчёте")]
public string? Blocks { get; set; }
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; } = null!;
}

View File

@ -17,7 +17,7 @@ namespace AsbCloudDb.Model
DbSet<Cluster> Clusters { get; }
DbSet<Company> Companies { get; }
DbSet<CompanyType> CompaniesTypes { get; }
DbSet<DailyReport.DailyReport> DailyReports { get; }
DbSet<DailyReport> DailyReports { get; }
DbSet<Deposit> Deposits { get; }
DbSet<DetectedOperation> DetectedOperations { get; }
DbSet<PlannedTrajectory> PlannedTrajectories { get; }