forked from ddrilling/AsbCloudServer
Изменения в слое работы с данными
1. Добавил модели для инструкций 2. Добавил инициализацию новых прав 3. Добавил новые миграции
This commit is contained in:
parent
bd4bb09509
commit
f94db74d6a
8548
AsbCloudDb/Migrations/20230810052950_Add_Manuals.Designer.cs
generated
Normal file
8548
AsbCloudDb/Migrations/20230810052950_Add_Manuals.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
167
AsbCloudDb/Migrations/20230810052950_Add_Manuals.cs
Normal file
167
AsbCloudDb/Migrations/20230810052950_Add_Manuals.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Add_Manuals : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "type",
|
||||
table: "t_file_category",
|
||||
type: "integer",
|
||||
nullable: true,
|
||||
comment: "0 = Инструкции");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "t_manual_folder",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
name = table.Column<string>(type: "text", nullable: false, comment: "Название папки"),
|
||||
id_parent = table.Column<int>(type: "integer", nullable: true, comment: "Родительская папки"),
|
||||
id_category = table.Column<int>(type: "integer", nullable: false, comment: "Категория")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_t_manual_folder", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_t_manual_folder_t_file_category_id_category",
|
||||
column: x => x.id_category,
|
||||
principalTable: "t_file_category",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_t_manual_folder_t_manual_folder_id_parent",
|
||||
column: x => x.id_parent,
|
||||
principalTable: "t_manual_folder",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
},
|
||||
comment: "Папка для инструкций");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "t_manual",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
name = table.Column<string>(type: "text", nullable: false, comment: "Название файла"),
|
||||
date_download = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "Дата загрузки файла"),
|
||||
id_category = table.Column<int>(type: "integer", nullable: true, comment: "Категория"),
|
||||
id_folder = table.Column<int>(type: "integer", nullable: true, comment: "Id папки инструкций")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_t_manual", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_t_manual_t_file_category_id_category",
|
||||
column: x => x.id_category,
|
||||
principalTable: "t_file_category",
|
||||
principalColumn: "id");
|
||||
table.ForeignKey(
|
||||
name: "FK_t_manual_t_manual_folder_id_folder",
|
||||
column: x => x.id_folder,
|
||||
principalTable: "t_manual_folder",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
},
|
||||
comment: "Инструкции");
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_file_category",
|
||||
columns: new[] { "id", "type", "name", "short_name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 30000, 0, "АСУ ТП", null },
|
||||
{ 30001, 0, "Технология бурения", null }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_permission",
|
||||
columns: new[] { "id", "description", "name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 523, "Разрешить редактирование инструкций", "Manual.edit" },
|
||||
{ 524, "Разрешить просмотр инструкций", "Manual.view" }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_relation_user_role_permission",
|
||||
columns: new[] { "id_permission", "id_user_role" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 523, 1 },
|
||||
{ 524, 1 }
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_t_manual_id_category",
|
||||
table: "t_manual",
|
||||
column: "id_category");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_t_manual_id_folder",
|
||||
table: "t_manual",
|
||||
column: "id_folder");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_t_manual_folder_id_category",
|
||||
table: "t_manual_folder",
|
||||
column: "id_category");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_t_manual_folder_id_parent",
|
||||
table: "t_manual_folder",
|
||||
column: "id_parent");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "t_manual");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "t_manual_folder");
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_file_category",
|
||||
keyColumn: "id",
|
||||
keyValue: 30000);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_file_category",
|
||||
keyColumn: "id",
|
||||
keyValue: 30001);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_relation_user_role_permission",
|
||||
keyColumns: new[] { "id_permission", "id_user_role" },
|
||||
keyValues: new object[] { 523, 1 });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_relation_user_role_permission",
|
||||
keyColumns: new[] { "id_permission", "id_user_role" },
|
||||
keyValues: new object[] { 524, 1 });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 523);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 524);
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "type",
|
||||
table: "t_file_category");
|
||||
}
|
||||
}
|
||||
}
|
@ -432,6 +432,11 @@ namespace AsbCloudDb.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("IdType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type")
|
||||
.HasComment("0 = Инструкции");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
@ -785,6 +790,18 @@ namespace AsbCloudDb.Migrations
|
||||
{
|
||||
Id = 20000,
|
||||
Name = "Справки по страницам"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 30000,
|
||||
IdType = 0,
|
||||
Name = "АСУ ТП"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 30001,
|
||||
IdType = 0,
|
||||
Name = "Технология бурения"
|
||||
});
|
||||
});
|
||||
|
||||
@ -1066,6 +1083,83 @@ namespace AsbCloudDb.Migrations
|
||||
b.HasComment("Ограничения по параметрам телеметрии");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Manuals.Manual", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateDownload")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_download")
|
||||
.HasComment("Дата загрузки файла");
|
||||
|
||||
b.Property<int?>("IdCategory")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_category")
|
||||
.HasComment("Категория");
|
||||
|
||||
b.Property<int?>("IdFolder")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_folder")
|
||||
.HasComment("Id папки инструкций");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name")
|
||||
.HasComment("Название файла");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IdCategory");
|
||||
|
||||
b.HasIndex("IdFolder");
|
||||
|
||||
b.ToTable("t_manual");
|
||||
|
||||
b.HasComment("Инструкции");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("IdCategory")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_category")
|
||||
.HasComment("Категория");
|
||||
|
||||
b.Property<int?>("IdParent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_parent")
|
||||
.HasComment("Родительская папки");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name")
|
||||
.HasComment("Название папки");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IdCategory");
|
||||
|
||||
b.HasIndex("IdParent");
|
||||
|
||||
b.ToTable("t_manual_folder");
|
||||
|
||||
b.HasComment("Папка для инструкций");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -2163,6 +2257,18 @@ namespace AsbCloudDb.Migrations
|
||||
Id = 522,
|
||||
Description = "Разрешить удаление всех настроек пользователя",
|
||||
Name = "UserSettings.delete"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 523,
|
||||
Description = "Разрешить редактирование инструкций",
|
||||
Name = "Manual.edit"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 524,
|
||||
Description = "Разрешить просмотр инструкций",
|
||||
Name = "Manual.view"
|
||||
});
|
||||
});
|
||||
|
||||
@ -3750,6 +3856,16 @@ namespace AsbCloudDb.Migrations
|
||||
{
|
||||
IdUserRole = 1,
|
||||
IdPermission = 522
|
||||
},
|
||||
new
|
||||
{
|
||||
IdUserRole = 1,
|
||||
IdPermission = 523
|
||||
},
|
||||
new
|
||||
{
|
||||
IdUserRole = 1,
|
||||
IdPermission = 524
|
||||
});
|
||||
});
|
||||
|
||||
@ -7682,6 +7798,40 @@ namespace AsbCloudDb.Migrations
|
||||
b.Navigation("Telemetry");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Manuals.Manual", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.FileCategory", "Category")
|
||||
.WithMany()
|
||||
.HasForeignKey("IdCategory");
|
||||
|
||||
b.HasOne("AsbCloudDb.Model.Manuals.ManualFolder", "Folder")
|
||||
.WithMany("Manuals")
|
||||
.HasForeignKey("IdFolder")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.Navigation("Category");
|
||||
|
||||
b.Navigation("Folder");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.FileCategory", "Category")
|
||||
.WithMany()
|
||||
.HasForeignKey("IdCategory")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AsbCloudDb.Model.Manuals.ManualFolder", "Parent")
|
||||
.WithMany("Children")
|
||||
.HasForeignKey("IdParent")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
b.Navigation("Category");
|
||||
|
||||
b.Navigation("Parent");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.MeasureCategory", "Category")
|
||||
@ -8307,6 +8457,13 @@ namespace AsbCloudDb.Migrations
|
||||
b.Navigation("FileMarks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b =>
|
||||
{
|
||||
b.Navigation("Children");
|
||||
|
||||
b.Navigation("Manuals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.MeasureCategory", b =>
|
||||
{
|
||||
b.Navigation("Measures");
|
||||
|
@ -3,6 +3,7 @@ using AsbCloudDb.Model.Subsystems;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
@ -77,6 +78,9 @@ namespace AsbCloudDb.Model
|
||||
public DbSet<HelpPage> HelpPages => Set<HelpPage>();
|
||||
public DbSet<Notification> Notifications => Set<Notification>();
|
||||
public DbSet<NotificationCategory> NotificationCategories => Set<NotificationCategory>();
|
||||
public DbSet<Manual> Manuals => Set<Manual>();
|
||||
public DbSet<ManualFolder> ManualFolders => Set<ManualFolder>();
|
||||
|
||||
|
||||
public AsbCloudDbContext() : base()
|
||||
{
|
||||
@ -388,6 +392,18 @@ namespace AsbCloudDb.Model
|
||||
entity.HasKey(x => new { x.IdWell, x.IdUser });
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ManualFolder>()
|
||||
.HasOne(mf => mf.Parent)
|
||||
.WithMany(mf => mf.Children)
|
||||
.HasForeignKey(mf => mf.IdParent)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<Manual>()
|
||||
.HasOne(m => m.Folder)
|
||||
.WithMany(f => f.Manuals)
|
||||
.HasForeignKey(m => m.IdFolder)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
DefaultData.DefaultContextData.Fill(modelBuilder);
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,10 @@
|
||||
new () {Id = 10042, Name = "Паспорт скважины (заполняется геологами)"},
|
||||
new () {Id = 10043, Name = "Фактические данные бурения (вставляются в паспорт скважины)"},
|
||||
|
||||
new () {Id = 20000, Name = "Справки по страницам"}
|
||||
new () {Id = 20000, Name = "Справки по страницам"},
|
||||
|
||||
new() { Id = 30000, Name = "АСУ ТП", IdType = FileCategory.IdFileCategoryTypeManuals},
|
||||
new() { Id = 30001, Name = "Технология бурения", IdType = FileCategory.IdFileCategoryTypeManuals}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +156,9 @@
|
||||
new() { Id = 521, Name = "HelpPage.edit", Description = "Разрешить создание справок по страницам"},
|
||||
|
||||
new() { Id = 522, Name = "UserSettings.delete", Description = "Разрешить удаление всех настроек пользователя"},
|
||||
|
||||
new() { Id = 523, Name = "Manual.edit", Description = "Разрешить редактирование инструкций" },
|
||||
new() { Id = 524, Name = "Manual.view", Description = "Разрешить просмотр инструкций"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ namespace AsbCloudDb.Model
|
||||
[Table("t_file_category"), Comment("Категории файлов")]
|
||||
public class FileCategory : IId
|
||||
{
|
||||
public const int IdFileCategoryTypeManuals = 0;
|
||||
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
@ -16,5 +18,8 @@ namespace AsbCloudDb.Model
|
||||
|
||||
[Column("short_name"), Comment("Короткое название категории")]
|
||||
public string? ShortName { get; set; }
|
||||
|
||||
[Column("type"), Comment("0 = Инструкции")]
|
||||
public int? IdType { get; set; }
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
@ -70,6 +71,8 @@ namespace AsbCloudDb.Model
|
||||
DbSet<HelpPage> HelpPages { get; }
|
||||
DbSet<Notification> Notifications { get; }
|
||||
DbSet<NotificationCategory> NotificationCategories { get; }
|
||||
DbSet<Manual> Manuals { get; }
|
||||
DbSet<ManualFolder> ManualFolders { get; }
|
||||
DatabaseFacade Database { get; }
|
||||
|
||||
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);
|
||||
|
32
AsbCloudDb/Model/Manuals/Manual.cs
Normal file
32
AsbCloudDb/Model/Manuals/Manual.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudDb.Model.Manuals;
|
||||
|
||||
[Table("t_manual"), Comment("Инструкции")]
|
||||
public class Manual : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("name"), Comment("Название файла")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Column("date_download"), Comment("Дата загрузки файла")]
|
||||
public DateTime DateDownload { get; set; }
|
||||
|
||||
[Column("id_category"), Comment("Категория")]
|
||||
public int? IdCategory { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdCategory))]
|
||||
public virtual FileCategory? Category { get; set; }
|
||||
|
||||
[Column("id_folder"), Comment("Id папки инструкций")]
|
||||
public int? IdFolder { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdFolder))]
|
||||
public virtual ManualFolder? Folder { get; set; }
|
||||
}
|
33
AsbCloudDb/Model/Manuals/ManualFolder.cs
Normal file
33
AsbCloudDb/Model/Manuals/ManualFolder.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudDb.Model.Manuals;
|
||||
|
||||
[Table("t_manual_folder"), Comment("Папка для инструкций")]
|
||||
public class ManualFolder : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("name"), Comment("Название папки")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Column("id_parent"), Comment("Родительская папки")]
|
||||
public int? IdParent { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdParent))]
|
||||
public virtual ManualFolder? Parent { get; set; }
|
||||
|
||||
[Column("id_category"), Comment("Категория")]
|
||||
public int IdCategory { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdCategory))]
|
||||
public virtual FileCategory Category { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<ManualFolder>? Children { get; set; }
|
||||
|
||||
public virtual ICollection<Manual>? Manuals { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user