Files
mws.backend.dotnet/infrastructure/Migrations/20260920085021_AddAuditLogs.cs
T
2026-09-20 16:21:15 +07:00

99 lines
4.2 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace mws.backend.dotnet.infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddAuditLogs : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "action_logs",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ActorUserId = table.Column<Guid>(type: "uuid", nullable: false),
ActorUsername = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Action = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
EntityType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
EntityId = table.Column<Guid>(type: "uuid", nullable: true),
EntityName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
IpAddress = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true),
UserAgent = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_action_logs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "login_logs",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Username = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: true),
Success = table.Column<bool>(type: "boolean", nullable: false),
FailureReason = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
IpAddress = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true),
UserAgent = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_login_logs", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_action_logs_Action",
table: "action_logs",
column: "Action");
migrationBuilder.CreateIndex(
name: "IX_action_logs_ActorUserId",
table: "action_logs",
column: "ActorUserId");
migrationBuilder.CreateIndex(
name: "IX_action_logs_CreatedAt",
table: "action_logs",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_action_logs_EntityType",
table: "action_logs",
column: "EntityType");
migrationBuilder.CreateIndex(
name: "IX_login_logs_CreatedAt",
table: "login_logs",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_login_logs_Success",
table: "login_logs",
column: "Success");
migrationBuilder.CreateIndex(
name: "IX_login_logs_Username",
table: "login_logs",
column: "Username");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "action_logs");
migrationBuilder.DropTable(
name: "login_logs");
}
}
}