6b9f27573b
- Integrated SignalR for real-time notification delivery to users.
100 lines
4.8 KiB
C#
100 lines
4.8 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Distribution.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddNotifications : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Notifications",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
Type = table.Column<string>(type: "varchar(60)", maxLength: 60, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Severity = table.Column<int>(type: "int", nullable: false),
|
|
Title = table.Column<string>(type: "varchar(150)", maxLength: 150, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Message = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
EntityType = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
EntityId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
Link = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
CreatedByUserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Notifications", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "NotificationRecipients",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_NotificationId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_UserId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
IsRead = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
ReadAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_NotificationRecipients", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_NotificationRecipients_Notifications_FK_NotificationId",
|
|
column: x => x.FK_NotificationId,
|
|
principalTable: "Notifications",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_NotificationRecipients_Users_FK_UserId",
|
|
column: x => x.FK_UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_NotificationRecipients_FK_NotificationId_FK_UserId",
|
|
table: "NotificationRecipients",
|
|
columns: new[] { "FK_NotificationId", "FK_UserId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_NotificationRecipients_FK_UserId_IsRead",
|
|
table: "NotificationRecipients",
|
|
columns: new[] { "FK_UserId", "IsRead" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Notifications_EntityType_EntityId",
|
|
table: "Notifications",
|
|
columns: new[] { "EntityType", "EntityId" });
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "NotificationRecipients");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Notifications");
|
|
|
|
}
|
|
}
|
|
}
|