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 InitialCreate : Migration
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
|
|
|
{
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "documents",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
ProjectId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
ParentId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
|
|
|
Title = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
|
|
|
Type = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
2026-09-12 20:58:10 +07:00
|
|
|
ContentHash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
|
|
|
ContentSize = table.Column<long>(type: "bigint", nullable: true),
|
|
|
|
|
UpdatedContentAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
2026-08-13 23:10:22 +07:00
|
|
|
CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
|
|
|
UpdatedBy = table.Column<Guid>(type: "uuid", nullable: true),
|
|
|
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_documents", x => x.Id);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_documents_documents_ParentId",
|
|
|
|
|
column: x => x.ParentId,
|
|
|
|
|
principalTable: "documents",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
2026-09-12 20:58:10 +07:00
|
|
|
name: "master_data",
|
2026-08-13 23:10:22 +07:00
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
2026-09-12 20:58:10 +07:00
|
|
|
Group = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
|
|
|
Label = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
|
|
|
Value = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
|
|
|
SortOrder = table.Column<int>(type: "integer", nullable: false),
|
|
|
|
|
IsActive = table.Column<bool>(type: "boolean", nullable: false),
|
2026-08-13 23:10:22 +07:00
|
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
|
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
2026-09-12 20:58:10 +07:00
|
|
|
table.PrimaryKey("PK_master_data", x => x.Id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
2026-08-13 23:10:22 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "users",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
Username = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
|
|
|
PasswordHash = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
|
|
|
DisplayName = table.Column<string>(type: "character varying(150)", maxLength: 150, nullable: false),
|
2026-09-12 20:58:10 +07:00
|
|
|
IsActive = table.Column<bool>(type: "boolean", nullable: false),
|
2026-08-13 23:10:22 +07:00
|
|
|
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_users", x => x.Id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
2026-09-12 20:58:10 +07:00
|
|
|
name: "role_permissions",
|
2026-08-13 23:10:22 +07:00
|
|
|
columns: table => new
|
|
|
|
|
{
|
2026-09-12 20:58:10 +07:00
|
|
|
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)
|
2026-08-13 23:10:22 +07:00
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
2026-09-12 20:58:10 +07:00
|
|
|
table.PrimaryKey("PK_role_permissions", x => new { x.RoleId, x.Screen });
|
2026-08-13 23:10:22 +07:00
|
|
|
table.ForeignKey(
|
2026-09-12 20:58:10 +07:00
|
|
|
name: "FK_role_permissions_roles_RoleId",
|
|
|
|
|
column: x => x.RoleId,
|
|
|
|
|
principalTable: "roles",
|
2026-08-13 23:10:22 +07:00
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
2026-09-12 20:58:10 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "projects",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
Name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
|
|
|
Description = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
|
|
|
|
Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
|
|
|
CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
|
|
|
UpdatedBy = table.Column<Guid>(type: "uuid", nullable: true),
|
|
|
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_projects", x => x.Id);
|
2026-08-13 23:10:22 +07:00
|
|
|
table.ForeignKey(
|
2026-09-12 20:58:10 +07:00
|
|
|
name: "FK_projects_users_CreatedBy",
|
|
|
|
|
column: x => x.CreatedBy,
|
2026-08-13 23:10:22 +07:00
|
|
|
principalTable: "users",
|
|
|
|
|
principalColumn: "Id",
|
2026-09-12 20:58:10 +07:00
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_projects_users_UpdatedBy",
|
|
|
|
|
column: x => x.UpdatedBy,
|
|
|
|
|
principalTable: "users",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
2026-08-13 23:10:22 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "tasks",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
ProjectId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
Title = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
|
|
|
Description = table.Column<string>(type: "text", nullable: true),
|
|
|
|
|
Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
|
|
|
Priority = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
|
|
|
AssigneeId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
|
|
|
DueDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
|
|
|
|
CreatedBy = table.Column<Guid>(type: "uuid", 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_tasks", x => x.Id);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_tasks_users_AssigneeId",
|
|
|
|
|
column: x => x.AssigneeId,
|
|
|
|
|
principalTable: "users",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.SetNull);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-12 20:58:10 +07:00
|
|
|
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.CreateTable(
|
|
|
|
|
name: "project_members",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
ProjectId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
|
|
|
Role = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_project_members", x => new { x.ProjectId, x.UserId });
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_project_members_projects_ProjectId",
|
|
|
|
|
column: x => x.ProjectId,
|
|
|
|
|
principalTable: "projects",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_project_members_users_UserId",
|
|
|
|
|
column: x => x.UserId,
|
|
|
|
|
principalTable: "users",
|
|
|
|
|
principalColumn: "Id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-13 23:10:22 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_documents_ParentId",
|
|
|
|
|
table: "documents",
|
|
|
|
|
column: "ParentId");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_documents_ProjectId_ParentId",
|
|
|
|
|
table: "documents",
|
|
|
|
|
columns: new[] { "ProjectId", "ParentId" });
|
|
|
|
|
|
2026-09-12 20:58:10 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_master_data_Group_Value",
|
|
|
|
|
table: "master_data",
|
|
|
|
|
columns: new[] { "Group", "Value" },
|
|
|
|
|
unique: true);
|
|
|
|
|
|
2026-08-13 23:10:22 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_project_members_UserId",
|
|
|
|
|
table: "project_members",
|
|
|
|
|
column: "UserId");
|
|
|
|
|
|
2026-09-12 20:58:10 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_projects_CreatedBy",
|
|
|
|
|
table: "projects",
|
|
|
|
|
column: "CreatedBy");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_projects_UpdatedBy",
|
|
|
|
|
table: "projects",
|
|
|
|
|
column: "UpdatedBy");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_roles_Name",
|
|
|
|
|
table: "roles",
|
|
|
|
|
column: "Name",
|
|
|
|
|
unique: true);
|
|
|
|
|
|
2026-08-13 23:10:22 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_tasks_AssigneeId",
|
|
|
|
|
table: "tasks",
|
|
|
|
|
column: "AssigneeId");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_tasks_ProjectId",
|
|
|
|
|
table: "tasks",
|
|
|
|
|
column: "ProjectId");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_tasks_Status",
|
|
|
|
|
table: "tasks",
|
|
|
|
|
column: "Status");
|
|
|
|
|
|
2026-09-12 20:58:10 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_user_roles_RoleId",
|
|
|
|
|
table: "user_roles",
|
|
|
|
|
column: "RoleId");
|
|
|
|
|
|
2026-08-13 23:10:22 +07:00
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_users_Username",
|
|
|
|
|
table: "users",
|
|
|
|
|
column: "Username",
|
|
|
|
|
unique: true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
|
|
|
{
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "documents");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
2026-09-12 20:58:10 +07:00
|
|
|
name: "master_data");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "project_member_permissions");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "role_permissions");
|
2026-08-13 23:10:22 +07:00
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "tasks");
|
|
|
|
|
|
2026-09-12 20:58:10 +07:00
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "user_roles");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "project_members");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "roles");
|
|
|
|
|
|
2026-08-13 23:10:22 +07:00
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "projects");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "users");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|