2026-08-13 23:10:22 +07:00
|
|
|
using System;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
|
|
|
|
|
|
#nullable disable
|
|
|
|
|
|
2026-08-19 23:25:08 +07:00
|
|
|
namespace mws.backend.dotnet.infrastructure.Migrations
|
2026-08-13 23:10:22 +07:00
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
2026-08-19 23:25:08 +07:00
|
|
|
public partial class AddUserRolesTable : Migration
|
2026-08-13 23:10:22 +07:00
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
|
|
|
{
|
2026-08-19 23:25:08 +07:00
|
|
|
migrationBuilder.DropForeignKey(
|
|
|
|
|
name: "FK_users_roles_RoleId",
|
|
|
|
|
table: "users");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropIndex(
|
|
|
|
|
name: "IX_users_RoleId",
|
|
|
|
|
table: "users");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropColumn(
|
|
|
|
|
name: "RoleId",
|
|
|
|
|
table: "users");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "user_roles",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
RoleId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_user_roles", x => new { x.UserId, x.RoleId });
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_user_roles_roles_RoleId",
|
|
|
|
|
column: x => x.RoleId,
|
|
|
|
|
principalTable: "roles",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_user_roles_users_UserId",
|
|
|
|
|
column: x => x.UserId,
|
|
|
|
|
principalTable: "users",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_user_roles_RoleId",
|
|
|
|
|
table: "user_roles",
|
|
|
|
|
column: "RoleId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
|
|
|
{
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "user_roles");
|
2026-08-13 23:10:22 +07:00
|
|
|
|
|
|
|
|
migrationBuilder.AddColumn<Guid>(
|
|
|
|
|
name: "RoleId",
|
|
|
|
|
table: "users",
|
|
|
|
|
type: "uuid",
|
|
|
|
|
nullable: false,
|
|
|
|
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_users_RoleId",
|
|
|
|
|
table: "users",
|
|
|
|
|
column: "RoleId");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
|
|
|
name: "FK_users_roles_RoleId",
|
|
|
|
|
table: "users",
|
|
|
|
|
column: "RoleId",
|
|
|
|
|
principalTable: "roles",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|