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

149 lines
6.3 KiB
C#

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.CreateTable(
name: "t_manual_directory",
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 родительской директории")
},
constraints: table =>
{
table.PrimaryKey("PK_t_manual_directory", x => x.id);
table.ForeignKey(
name: "FK_t_manual_directory_t_manual_directory_id_parent",
column: x => x.id_parent,
principalTable: "t_manual_directory",
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_directory = table.Column<int>(type: "integer", nullable: false, comment: "Id директории"),
id_category = table.Column<int>(type: "integer", nullable: false, comment: "Id категории файла"),
id_author = table.Column<int>(type: "integer", nullable: false, 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",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_manual_t_manual_directory_id_directory",
column: x => x.id_directory,
principalTable: "t_manual_directory",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_manual_t_user_id_author",
column: x => x.id_author,
principalTable: "t_user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Инструкции");
migrationBuilder.InsertData(
table: "t_file_category",
columns: new[] { "id", "name", "short_name" },
values: new object[] { 30000, "Инструкции", null });
migrationBuilder.InsertData(
table: "t_permission",
columns: new[] { "id", "description", "name" },
values: new object[,]
{
{ 523, "Разрешить редактирование инструкций", "Manual.edit" },
{ 524, "Разрешить получение инструкций", "Manual.get" }
});
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_author",
table: "t_manual",
column: "id_author");
migrationBuilder.CreateIndex(
name: "IX_t_manual_id_category",
table: "t_manual",
column: "id_category");
migrationBuilder.CreateIndex(
name: "IX_t_manual_id_directory",
table: "t_manual",
column: "id_directory");
migrationBuilder.CreateIndex(
name: "IX_t_manual_directory_id_parent",
table: "t_manual_directory",
column: "id_parent");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_manual");
migrationBuilder.DropTable(
name: "t_manual_directory");
migrationBuilder.DeleteData(
table: "t_file_category",
keyColumn: "id",
keyValue: 30000);
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);
}
}
}