Files
mws.backend.dotnet/infrastructure/Migrations/20260812130925_SplitProjectMemberPermissions.cs
T

106 lines
4.2 KiB
C#
Raw Normal View History

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 />
public partial class SplitProjectMemberPermissions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "project_member_permissions",
columns: table => new
{
ProjectId = table.Column<Guid>(type: "uuid", nullable: false),
UserId = 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_project_member_permissions", x => new { x.ProjectId, x.UserId, x.Screen });
table.ForeignKey(
name: "FK_project_member_permissions_project_members_ProjectId_UserId",
columns: x => new { x.ProjectId, x.UserId },
principalTable: "project_members",
principalColumns: new[] { "ProjectId", "UserId" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.Sql("""
INSERT INTO "project_member_permissions" ("ProjectId", "UserId", "Screen", "CanView", "CanCreate", "CanEdit", "CanDelete")
SELECT "ProjectId", "UserId", 'documents', "CanViewDocuments", "CanCreateDocuments", "CanEditDocuments", "CanDeleteDocuments"
FROM "project_members";
""");
migrationBuilder.DropColumn(
name: "CanCreateDocuments",
table: "project_members");
migrationBuilder.DropColumn(
name: "CanDeleteDocuments",
table: "project_members");
migrationBuilder.DropColumn(
name: "CanEditDocuments",
table: "project_members");
migrationBuilder.DropColumn(
name: "CanViewDocuments",
table: "project_members");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "CanCreateDocuments",
table: "project_members",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "CanDeleteDocuments",
table: "project_members",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "CanEditDocuments",
table: "project_members",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "CanViewDocuments",
table: "project_members",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.Sql("""
UPDATE "project_members" m
SET "CanViewDocuments" = p."CanView",
"CanCreateDocuments" = p."CanCreate",
"CanEditDocuments" = p."CanEdit",
"CanDeleteDocuments" = p."CanDelete"
FROM "project_member_permissions" p
WHERE p."ProjectId" = m."ProjectId" AND p."UserId" = m."UserId" AND p."Screen" = 'documents';
""");
migrationBuilder.DropTable(
name: "project_member_permissions");
}
}
}