using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using System.Collections.Generic; namespace AsbCloudDb.Migrations { public partial class Renamed_Permissions_Tables : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "t_relation_user_role_permission"); migrationBuilder.DropPrimaryKey( name: "PK_t_permission", table: "t_permission"); migrationBuilder.DropColumn( name: "bit_description", table: "t_permission"); migrationBuilder.DropColumn( name: "description", table: "t_permission"); migrationBuilder.DropColumn( name: "name", table: "t_permission"); migrationBuilder.RenameColumn( name: "id", table: "t_permission", newName: "permission_value"); migrationBuilder.AlterTable( name: "t_permission", comment: "Отношение ролей пользователей и разрешений доступа", oldComment: "Разрешения на доступ к данным"); migrationBuilder.AlterColumn( name: "permission_value", table: "t_permission", type: "integer", nullable: false, oldClrType: typeof(int), oldType: "integer") .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); migrationBuilder.AddColumn( name: "id_user_role", table: "t_permission", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "id_permission", 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" }); migrationBuilder.CreateTable( name: "t_permission_info", columns: table => new { id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), name = table.Column(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Название"), description = table.Column(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Краткое описание"), bit_description = table.Column>(type: "jsonb", nullable: true, comment: "Описание каждого бита разрешений") }, constraints: table => { table.PrimaryKey("PK_t_permission_info", x => x.id); }, comment: "Разрешения на доступ к данным"); migrationBuilder.CreateIndex( name: "IX_t_permission_id_permission", table: "t_permission", column: "id_permission"); migrationBuilder.AddForeignKey( name: "FK_t_permission_t_permission_info_id_permission", table: "t_permission", column: "id_permission", 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); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_t_permission_t_permission_info_id_permission", 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", table: "t_permission"); migrationBuilder.DropColumn( name: "id_user_role", table: "t_permission"); migrationBuilder.DropColumn( name: "id_permission", table: "t_permission"); migrationBuilder.RenameColumn( name: "permission_value", table: "t_permission", newName: "id"); migrationBuilder.AlterTable( name: "t_permission", comment: "Разрешения на доступ к данным", oldComment: "Отношение ролей пользователей и разрешений доступа"); migrationBuilder.AlterColumn( name: "id", table: "t_permission", type: "integer", nullable: false, oldClrType: typeof(int), oldType: "integer") .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); migrationBuilder.AddColumn( name: "bit_description", table: "t_permission", type: "jsonb", nullable: true, comment: "Описание каждого бита разрешений"); migrationBuilder.AddColumn( name: "description", table: "t_permission", type: "character varying(255)", maxLength: 255, nullable: true, comment: "Краткое описание"); migrationBuilder.AddColumn( 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(type: "integer", nullable: false), id_permission = table.Column(type: "integer", nullable: false), permission_value = table.Column(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"); } } }