DD.WellWorkover.Cloud/AsbCloudDb/Migrations/20211126101932_Changed_Permissions_To_Bit_Collection.cs
2021-11-26 17:05:41 +05:00

134 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace AsbCloudDb.Migrations
{
public partial class Changed_Permissions_To_Bit_Collection : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_relation_user_role_permission");
migrationBuilder.DropColumn(
name: "caption",
table: "t_permission");
migrationBuilder.DropColumn(
name: "type",
table: "t_permission");
migrationBuilder.AlterTable(
name: "t_permission",
comment: "Описание битов разрешений для ролей пользователей",
oldComment: "Разрешения на доступ к данным");
migrationBuilder.AddColumn<long>(
name: "permissions",
table: "t_user_role",
type: "bigint",
nullable: false,
defaultValue: 0L,
comment: "Десятичное число, хранящее список разрешений для роли (в двоичном виде)");
migrationBuilder.AddColumn<string>(
name: "description",
table: "t_permission",
type: "character varying(255)",
maxLength: 255,
nullable: true,
comment: "Описание разрешений");
migrationBuilder.AddColumn<string>(
name: "index",
table: "t_permission",
type: "text",
nullable: true,
comment: "Порядковый номер бита. \n В нем 0-запрещено, 1-разрешено.");
migrationBuilder.InsertData(
table: "t_relation_user_user_role",
columns: new[] { "id", "id_user", "id_user_role" },
values: new object[] { 1, 1, 2 });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "t_relation_user_user_role",
keyColumn: "id",
keyValue: 1);
migrationBuilder.DropColumn(
name: "permissions",
table: "t_user_role");
migrationBuilder.DropColumn(
name: "description",
table: "t_permission");
migrationBuilder.DropColumn(
name: "index",
table: "t_permission");
migrationBuilder.AlterTable(
name: "t_permission",
comment: "Разрешения на доступ к данным",
oldComment: "Описание битов разрешений для ролей пользователей");
migrationBuilder.AddColumn<string>(
name: "caption",
table: "t_permission",
type: "character varying(255)",
maxLength: 255,
nullable: true,
comment: "Название");
migrationBuilder.AddColumn<int>(
name: "type",
table: "t_permission",
type: "integer",
nullable: false,
defaultValue: 0,
comment: "1-чтение, 2-запись, 3-чтение и запись");
migrationBuilder.CreateTable(
name: "t_relation_user_role_permission",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_permission = table.Column<int>(type: "integer", nullable: false),
id_user_role = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_t_relation_user_role_permission", x => x.id);
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");
migrationBuilder.CreateIndex(
name: "IX_t_relation_user_role_permission_id_user_role",
table: "t_relation_user_role_permission",
column: "id_user_role");
}
}
}