DD.WellWorkover.Cloud/AsbCloudDb/Migrations/20211129122956_Fixed_Role_Permissions_Value.cs
2021-11-29 17:34:53 +05:00

224 lines
8.1 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace AsbCloudDb.Migrations
{
public partial class Fixed_Role_Permissions_Value : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_t_relation_user_user_role",
table: "t_relation_user_user_role");
migrationBuilder.DropIndex(
name: "IX_t_relation_user_user_role_id_user",
table: "t_relation_user_user_role");
migrationBuilder.DropPrimaryKey(
name: "PK_t_relation_user_role_permission",
table: "t_relation_user_role_permission");
migrationBuilder.DropIndex(
name: "IX_t_relation_user_role_permission_id_user_role",
table: "t_relation_user_role_permission");
migrationBuilder.DropColumn(
name: "id",
table: "t_relation_user_user_role");
migrationBuilder.DropColumn(
name: "type",
table: "t_permission");
migrationBuilder.RenameColumn(
name: "role_type",
table: "t_user_role",
newName: "id_type");
migrationBuilder.RenameColumn(
name: "id",
table: "t_relation_user_role_permission",
newName: "permission_value");
migrationBuilder.RenameColumn(
name: "caption",
table: "t_permission",
newName: "name");
migrationBuilder.AlterColumn<int>(
name: "id_parent",
table: "t_user_role",
type: "integer",
nullable: true,
comment: "От какой роли унаследована данная роль",
oldClrType: typeof(int),
oldType: "integer",
oldComment: "От какой роли унаследована данная роль");
migrationBuilder.AlterColumn<int>(
name: "permission_value",
table: "t_relation_user_role_permission",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddColumn<string>(
name: "bit_description",
table: "t_permission",
type: "jsonb",
nullable: true,
comment: "Описание каждого бита разрешений");
migrationBuilder.AddColumn<string>(
name: "description",
table: "t_permission",
type: "character varying(255)",
maxLength: 255,
nullable: true,
comment: "Краткое описание");
migrationBuilder.AddPrimaryKey(
name: "PK_t_relation_user_user_role",
table: "t_relation_user_user_role",
columns: new[] { "id_user", "id_user_role" });
migrationBuilder.AddPrimaryKey(
name: "PK_t_relation_user_role_permission",
table: "t_relation_user_role_permission",
columns: new[] { "id_user_role", "id_permission" });
migrationBuilder.InsertData(
table: "t_relation_user_user_role",
columns: new[] { "id_user", "id_user_role" },
values: new object[] { 1, 2 });
migrationBuilder.UpdateData(
table: "t_user_role",
keyColumn: "id",
keyValue: 1,
column: "id_parent",
value: null);
migrationBuilder.UpdateData(
table: "t_user_role",
keyColumn: "id",
keyValue: 2,
column: "id_parent",
value: null);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_t_relation_user_user_role",
table: "t_relation_user_user_role");
migrationBuilder.DropPrimaryKey(
name: "PK_t_relation_user_role_permission",
table: "t_relation_user_role_permission");
migrationBuilder.DeleteData(
table: "t_relation_user_user_role",
keyColumns: new[] { "id_user", "id_user_role" },
keyValues: new object[] { 1, 2 });
migrationBuilder.DropColumn(
name: "bit_description",
table: "t_permission");
migrationBuilder.DropColumn(
name: "description",
table: "t_permission");
migrationBuilder.RenameColumn(
name: "id_type",
table: "t_user_role",
newName: "role_type");
migrationBuilder.RenameColumn(
name: "permission_value",
table: "t_relation_user_role_permission",
newName: "id");
migrationBuilder.RenameColumn(
name: "name",
table: "t_permission",
newName: "caption");
migrationBuilder.AlterColumn<int>(
name: "id_parent",
table: "t_user_role",
type: "integer",
nullable: false,
defaultValue: 0,
comment: "От какой роли унаследована данная роль",
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true,
oldComment: "От какой роли унаследована данная роль");
migrationBuilder.AddColumn<int>(
name: "id",
table: "t_relation_user_user_role",
type: "integer",
nullable: false,
defaultValue: 0)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AlterColumn<int>(
name: "id",
table: "t_relation_user_role_permission",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddColumn<int>(
name: "type",
table: "t_permission",
type: "integer",
nullable: false,
defaultValue: 0,
comment: "1-чтение, 2-запись, 3-чтение и запись");
migrationBuilder.AddPrimaryKey(
name: "PK_t_relation_user_user_role",
table: "t_relation_user_user_role",
column: "id");
migrationBuilder.AddPrimaryKey(
name: "PK_t_relation_user_role_permission",
table: "t_relation_user_role_permission",
column: "id");
migrationBuilder.UpdateData(
table: "t_user_role",
keyColumn: "id",
keyValue: 1,
column: "id_parent",
value: 0);
migrationBuilder.UpdateData(
table: "t_user_role",
keyColumn: "id",
keyValue: 2,
column: "id_parent",
value: 0);
migrationBuilder.CreateIndex(
name: "IX_t_relation_user_user_role_id_user",
table: "t_relation_user_user_role",
column: "id_user");
migrationBuilder.CreateIndex(
name: "IX_t_relation_user_role_permission_id_user_role",
table: "t_relation_user_role_permission",
column: "id_user_role");
}
}
}