DD.WellWorkover.Cloud/AsbCloudDb/Migrations/20211215111416_RemovedPermissionValues.cs

215 lines
8.6 KiB
C#
Raw Normal View History

2022-04-11 18:00:34 +05:00
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
2022-04-11 18:00:34 +05:00
using System.Collections.Generic;
namespace AsbCloudDb.Migrations
{
public partial class RemovedPermissionValues : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_t_permission_t_permission_info_id_permission_info",
table: "t_permission");
migrationBuilder.DropForeignKey(
name: "FK_t_permission_t_user_role_id_user_role",
table: "t_permission");
migrationBuilder.DropTable(
name: "t_permission_info");
migrationBuilder.DropPrimaryKey(
name: "PK_t_permission",
table: "t_permission");
migrationBuilder.DropIndex(
name: "IX_t_permission_id_permission_info",
table: "t_permission");
migrationBuilder.DropColumn(
name: "id_user_role",
table: "t_permission");
migrationBuilder.DropColumn(
name: "id_permission_info",
table: "t_permission");
migrationBuilder.RenameColumn(
name: "value",
table: "t_permission",
newName: "id");
migrationBuilder.AlterTable(
name: "t_permission",
comment: "Разрешения на доступ к данным",
oldComment: "Отношение ролей пользователей и разрешений доступа");
migrationBuilder.AddColumn<int>(
name: "id",
table: "t_relation_user_user_role",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AlterColumn<int>(
name: "id",
table: "t_permission",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddColumn<string>(
name: "description",
table: "t_permission",
type: "character varying(255)",
maxLength: 255,
nullable: true,
comment: "Краткое описание");
migrationBuilder.AddColumn<string>(
name: "name",
table: "t_permission",
type: "character varying(255)",
maxLength: 255,
nullable: true,
comment: "Название");
migrationBuilder.AddPrimaryKey(
name: "PK_t_permission",
table: "t_permission",
column: "id");
migrationBuilder.CreateTable(
name: "t_relation_user_role_permission",
columns: table => new
{
id_user_role = table.Column<int>(type: "integer", nullable: false),
id_permission = table.Column<int>(type: "integer", nullable: false),
id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_t_relation_user_role_permission", x => new { x.id_user_role, x.id_permission });
table.ForeignKey(
name: "FK_t_relation_user_role_permission_t_permission_id_permission",
column: x => x.id_permission,
principalTable: "t_permission",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_relation_user_role_permission_t_user_role_id_user_role",
column: x => x.id_user_role,
principalTable: "t_user_role",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Отношение ролей пользователей и разрешений доступа");
migrationBuilder.CreateIndex(
name: "IX_t_relation_user_role_permission_id_permission",
table: "t_relation_user_role_permission",
column: "id_permission");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_relation_user_role_permission");
migrationBuilder.DropPrimaryKey(
name: "PK_t_permission",
table: "t_permission");
migrationBuilder.DropColumn(
name: "id",
table: "t_relation_user_user_role");
migrationBuilder.DropColumn(
name: "description",
table: "t_permission");
migrationBuilder.DropColumn(
name: "name",
table: "t_permission");
migrationBuilder.RenameColumn(
name: "id",
table: "t_permission",
newName: "value");
migrationBuilder.AlterTable(
name: "t_permission",
comment: "Отношение ролей пользователей и разрешений доступа",
oldComment: "Разрешения на доступ к данным");
migrationBuilder.AlterColumn<int>(
name: "value",
table: "t_permission",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddColumn<int>(
name: "id_user_role",
table: "t_permission",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "id_permission_info",
table: "t_permission",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddPrimaryKey(
name: "PK_t_permission",
table: "t_permission",
columns: new[] { "id_user_role", "id_permission_info" });
migrationBuilder.CreateTable(
name: "t_permission_info",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
bit_description = table.Column<IDictionary<int, string>>(type: "jsonb", nullable: true, comment: "Описание каждого бита разрешений"),
description = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Краткое описание"),
name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Название")
},
constraints: table =>
{
table.PrimaryKey("PK_t_permission_info", x => x.id);
},
comment: "Разрешения на доступ к данным");
migrationBuilder.CreateIndex(
name: "IX_t_permission_id_permission_info",
table: "t_permission",
column: "id_permission_info");
migrationBuilder.AddForeignKey(
name: "FK_t_permission_t_permission_info_id_permission_info",
table: "t_permission",
column: "id_permission_info",
principalTable: "t_permission_info",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_t_permission_t_user_role_id_user_role",
table: "t_permission",
column: "id_user_role",
principalTable: "t_user_role",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
}
}
}