Files
mws.backend.dotnet/mws.infrastructure/Migrations/20260811133605_AddRolesAndPermissions.cs
T

112 lines
4.0 KiB
C#
Raw Normal View History

2026-08-13 23:10:22 +07:00
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Mws.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddRolesAndPermissions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsActive",
table: "users",
type: "boolean",
nullable: false,
defaultValue: true);
migrationBuilder.AddColumn<Guid>(
name: "RoleId",
table: "users",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.CreateTable(
name: "roles",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
IsSystem = table.Column<bool>(type: "boolean", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_roles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "role_permissions",
columns: table => new
{
RoleId = table.Column<Guid>(type: "uuid", nullable: false),
Screen = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
CanView = table.Column<bool>(type: "boolean", nullable: false),
CanCreate = table.Column<bool>(type: "boolean", nullable: false),
CanEdit = table.Column<bool>(type: "boolean", nullable: false),
CanDelete = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_role_permissions", x => new { x.RoleId, x.Screen });
table.ForeignKey(
name: "FK_role_permissions_roles_RoleId",
column: x => x.RoleId,
principalTable: "roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_users_RoleId",
table: "users",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_roles_Name",
table: "roles",
column: "Name",
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_users_roles_RoleId",
table: "users",
column: "RoleId",
principalTable: "roles",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_users_roles_RoleId",
table: "users");
migrationBuilder.DropTable(
name: "role_permissions");
migrationBuilder.DropTable(
name: "roles");
migrationBuilder.DropIndex(
name: "IX_users_RoleId",
table: "users");
migrationBuilder.DropColumn(
name: "IsActive",
table: "users");
migrationBuilder.DropColumn(
name: "RoleId",
table: "users");
}
}
}