From 5811d878180a85af5c41b9cb3b8f272d589539e9 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 17 Dec 2020 11:21:14 +0200 Subject: Roles are now in a seperate table, user can contain multiple roles (BUT JWT doesn't support mutiple yet), added migrations, userrepository returns user roles with the user --- .../Migrations/20201217083429_UserRoleTest.cs | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/DevHive.Web/Migrations/20201217083429_UserRoleTest.cs (limited to 'src/DevHive.Web/Migrations/20201217083429_UserRoleTest.cs') diff --git a/src/DevHive.Web/Migrations/20201217083429_UserRoleTest.cs b/src/DevHive.Web/Migrations/20201217083429_UserRoleTest.cs new file mode 100644 index 0000000..7c8e77a --- /dev/null +++ b/src/DevHive.Web/Migrations/20201217083429_UserRoleTest.cs @@ -0,0 +1,134 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Web.Migrations +{ + public partial class UserRoleTest : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Role", + table: "AspNetUsers"); + + migrationBuilder.AddColumn( + name: "Name", + table: "Technologies", + type: "text", + nullable: true); + + migrationBuilder.AlterColumn( + name: "UserName", + table: "AspNetUsers", + type: "character varying(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "LastName", + table: "AspNetUsers", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "FirstName", + table: "AspNetUsers", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.CreateTable( + name: "RoleUser", + columns: table => new + { + RolesId = table.Column(type: "uuid", nullable: false), + UsersId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RoleUser", x => new { x.RolesId, x.UsersId }); + table.ForeignKey( + name: "FK_RoleUser_AspNetRoles_RolesId", + column: x => x.RolesId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RoleUser_AspNetUsers_UsersId", + column: x => x.UsersId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoles_Id", + table: "AspNetRoles", + column: "Id", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_RoleUser_UsersId", + table: "RoleUser", + column: "UsersId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RoleUser"); + + migrationBuilder.DropIndex( + name: "IX_AspNetRoles_Id", + table: "AspNetRoles"); + + migrationBuilder.DropColumn( + name: "Name", + table: "Technologies"); + + migrationBuilder.AlterColumn( + name: "UserName", + table: "AspNetUsers", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "LastName", + table: "AspNetUsers", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "FirstName", + table: "AspNetUsers", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "Role", + table: "AspNetUsers", + type: "text", + nullable: true); + } + } +} -- cgit v1.2.3