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( name: "permissions", table: "t_user_role", type: "bigint", nullable: false, defaultValue: 0L, comment: "Десятичное число, хранящее список разрешений для роли (в двоичном виде)"); migrationBuilder.AddColumn( name: "description", table: "t_permission", type: "character varying(255)", maxLength: 255, nullable: true, comment: "Описание разрешений"); migrationBuilder.AddColumn( 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( name: "caption", table: "t_permission", type: "character varying(255)", maxLength: 255, nullable: true, comment: "Название"); migrationBuilder.AddColumn( 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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), id_permission = table.Column(type: "integer", nullable: false), id_user_role = table.Column(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"); } } }