DD.WellWorkover.Cloud/AsbCloudDb/Migrations/20230810052950_Add_Manuals.cs

168 lines
6.9 KiB
C#
Raw Normal View History

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");
}
}
}