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

1. Добавлена новая сущность
2. Добавлены новые права
3. Добавлена новая миграция
This commit is contained in:
Степанов Дмитрий 2023-12-04 16:55:56 +05:00
parent 15d329999b
commit 0767344daf
7 changed files with 9371 additions and 4 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Add_WellSectionPlan : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_well_section_plan",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
id_section_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
id_user = table.Column<int>(type: "integer", nullable: false, comment: "Id пользователя"),
date_last_update = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "Дата последнего обновления"),
depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Начальная глубина бурения, м"),
depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Конечная глубина бурения, м"),
outer_diameter = table.Column<double>(type: "double precision", nullable: true, comment: "Внешний диаметр"),
inner_diameter = table.Column<double>(type: "double precision", nullable: true, comment: "Внутренний диаметр")
},
constraints: table =>
{
table.PrimaryKey("PK_t_well_section_plan", x => x.id);
table.ForeignKey(
name: "FK_t_well_section_plan_t_well_id_well",
column: x => x.id_well,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_well_section_plan_t_well_section_type_id_section_type",
column: x => x.id_section_type,
principalTable: "t_well_section_type",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "t_permission",
columns: new[] { "id", "description", "name" },
values: new object[,]
{
{ 530, "Разрешение на редактирование плановой конструкции скважины", "WellSectionPlan.edit" },
{ 531, "Разрешение на удаление плановой конструкции скважины", "WellSectionPlan.delete" }
});
migrationBuilder.InsertData(
table: "t_relation_user_role_permission",
columns: new[] { "id_permission", "id_user_role" },
values: new object[,]
{
{ 530, 1 },
{ 531, 1 }
});
migrationBuilder.CreateIndex(
name: "IX_t_well_section_plan_id_section_type",
table: "t_well_section_plan",
column: "id_section_type");
migrationBuilder.CreateIndex(
name: "IX_t_well_section_plan_id_well_id_section_type",
table: "t_well_section_plan",
columns: new[] { "id_well", "id_section_type" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_well_section_plan");
migrationBuilder.DeleteData(
table: "t_relation_user_role_permission",
keyColumns: new[] { "id_permission", "id_user_role" },
keyValues: new object[] { 530, 1 });
migrationBuilder.DeleteData(
table: "t_relation_user_role_permission",
keyColumns: new[] { "id_permission", "id_user_role" },
keyValues: new object[] { 531, 1 });
migrationBuilder.DeleteData(
table: "t_permission",
keyColumn: "id",
keyValue: 530);
migrationBuilder.DeleteData(
table: "t_permission",
keyColumn: "id",
keyValue: 531);
}
}
}

View File

@ -2441,6 +2441,18 @@ namespace AsbCloudDb.Migrations
Id = 529,
Description = "Разрешение на получение отчетов drill test",
Name = "DrillTestReport.get"
},
new
{
Id = 530,
Description = "Разрешение на редактирование плановой конструкции скважины",
Name = "WellSectionPlan.edit"
},
new
{
Id = 531,
Description = "Разрешение на удаление плановой конструкции скважины",
Name = "WellSectionPlan.delete"
});
});
@ -4112,6 +4124,16 @@ namespace AsbCloudDb.Migrations
{
IdUserRole = 1,
IdPermission = 529
},
new
{
IdUserRole = 1,
IdPermission = 530
},
new
{
IdUserRole = 1,
IdPermission = 531
});
});
@ -7004,6 +7026,65 @@ namespace AsbCloudDb.Migrations
});
});
modelBuilder.Entity("AsbCloudDb.Model.WellSections.WellSectionPlan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<double>("DepthEnd")
.HasColumnType("double precision")
.HasColumnName("depth_end")
.HasComment("Конечная глубина бурения, м");
b.Property<double>("DepthStart")
.HasColumnType("double precision")
.HasColumnName("depth_start")
.HasComment("Начальная глубина бурения, м");
b.Property<int>("IdSectionType")
.HasColumnType("integer")
.HasColumnName("id_section_type")
.HasComment("Тип секции");
b.Property<int>("IdUser")
.HasColumnType("integer")
.HasColumnName("id_user")
.HasComment("Id пользователя");
b.Property<int>("IdWell")
.HasColumnType("integer")
.HasColumnName("id_well")
.HasComment("Id скважины");
b.Property<double?>("InnerDiameter")
.HasColumnType("double precision")
.HasColumnName("inner_diameter")
.HasComment("Внутренний диаметр");
b.Property<DateTimeOffset?>("LastUpdateDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_last_update")
.HasComment("Дата последнего обновления");
b.Property<double?>("OuterDiameter")
.HasColumnType("double precision")
.HasColumnName("outer_diameter")
.HasComment("Внешний диаметр");
b.HasKey("Id");
b.HasIndex("IdSectionType");
b.HasIndex("IdWell", "IdSectionType")
.IsUnique();
b.ToTable("t_well_section_plan");
});
modelBuilder.Entity("AsbCloudDb.Model.WellSectionType", b =>
{
b.Property<int>("Id")
@ -8783,6 +8864,25 @@ namespace AsbCloudDb.Migrations
b.Navigation("Parent");
});
modelBuilder.Entity("AsbCloudDb.Model.WellSections.WellSectionPlan", b =>
{
b.HasOne("AsbCloudDb.Model.WellSectionType", "SectionType")
.WithMany()
.HasForeignKey("IdSectionType")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.Well", "Well")
.WithMany()
.HasForeignKey("IdWell")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SectionType");
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.WITS.Record1", b =>
{
b.HasOne("AsbCloudDb.Model.Telemetry", "Telemetry")

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using AsbCloudDb.Model.DailyReports;
using AsbCloudDb.Model.Manuals;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudDb.Model.WellSections;
namespace AsbCloudDb.Model
{
@ -84,6 +85,7 @@ namespace AsbCloudDb.Model
public DbSet<Manual> Manuals => Set<Manual>();
public DbSet<ManualDirectory> ManualDirectories => Set<ManualDirectory>();
public DbSet<Contact> Contacts => Set<Contact>();
public DbSet<WellSectionPlan> PlanWellSections => Set<WellSectionPlan>();
public DbSet<DrillTest> DrillTests => Set<DrillTest>();
public AsbCloudDbContext() : base()
@ -429,6 +431,10 @@ namespace AsbCloudDb.Model
.HasJsonConversion();
});
modelBuilder.Entity<WellSectionPlan>()
.HasIndex(w => new { w.IdWell, w.IdSectionType })
.IsUnique();
DefaultData.DefaultContextData.Fill(modelBuilder);
}

View File

@ -158,11 +158,14 @@
new (){ Id = 525, Name = "ProcessMap.editCompletedWell", Description = "Разрешение на редактирование РТК у завершенной скважины"},
new (){ Id = 526, Name = "WellOperation.editCompletedWell", Description = "Разрешение на редактирование операций у завершенной скважины"},
new() { Id = 527, Name = "Manual.delete", Description = "Разрешение на удаление инструкций"},
new (){ Id = 528, Name="WellContact.delete", Description="Разрешение на удаление контакта"},
new (){ Id = 529, Name="DrillTestReport.get", Description="Разрешение на получение отчетов drill test"},
new() { Id = 527, Name = "Manual.delete", Description = "Разрешение на удаление инструкций" },
new() { Id = 528, Name = "WellContact.delete", Description = "Разрешение на удаление контакта" },
new() { Id = 529, Name = "DrillTestReport.get", Description = "Разрешение на получение отчетов drill test" },
new() { Id = 530, Name = "WellSectionPlan.edit", Description = "Разрешение на редактирование плановой конструкции скважины"},
new() { Id = 531, Name = "WellSectionPlan.delete", Description = "Разрешение на удаление плановой конструкции скважины"}
};
}
}

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using AsbCloudDb.Model.DailyReports;
using AsbCloudDb.Model.Manuals;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudDb.Model.WellSections;
namespace AsbCloudDb.Model
{
@ -78,6 +79,7 @@ namespace AsbCloudDb.Model
DbSet<ManualDirectory> ManualDirectories { get; }
DbSet<Contact> Contacts { get; }
DbSet<DrillTest> DrillTests { get; }
DbSet<WellSectionPlan> PlanWellSections { get; }
DatabaseFacade Database { get; }
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);

View File

@ -0,0 +1,45 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudDb.Model.WellSections;
[Table("t_well_section_plan")]
public class WellSectionPlan : IId,
IWellRelated
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("id_well"), Comment("Id скважины")]
public int IdWell { get; set; }
[Column("id_section_type"), Comment("Тип секции")]
public int IdSectionType { get; set; }
[Column("id_user"), Comment("Id пользователя")]
public int IdUser { get; set; }
[Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")]
public DateTimeOffset? LastUpdateDate { get; set; }
[Column("depth_start"), Comment("Начальная глубина бурения, м")]
public double DepthStart { get; set; }
[Column("depth_end"), Comment("Конечная глубина бурения, м")]
public double DepthEnd { get; set; }
[Column("outer_diameter"), Comment("Внешний диаметр")]
public double? OuterDiameter { get; set; }
[Column("inner_diameter"), Comment("Внутренний диаметр")]
public double? InnerDiameter { get; set; }
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; } = null!;
[ForeignKey(nameof(IdSectionType))]
public virtual WellSectionType SectionType { get; set; } = null!;
}