using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations.AppDb
{
///
public partial class AddChatRoomDomain : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChatBan",
columns: table => new
{
ID = table.Column(type: "int", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
MemberID = table.Column(type: "int", nullable: false, comment: "제재 대상 회원 ID"),
RoomKey = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true, comment: "제재 룸 키 (NULL=전체)"),
Reason = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false, comment: "제재 사유"),
ExpiresAt = table.Column(type: "datetime2", nullable: true),
CreatedBy = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "제재 등록자"),
CreatedAt = table.Column(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChatBan", x => x.ID);
table.ForeignKey(
name: "FK_ChatBan_Member_MemberID",
column: x => x.MemberID,
principalTable: "Member",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
},
comment: "채팅 제재 (RoomKey NULL=전체, ExpiresAt NULL=무기한)");
migrationBuilder.CreateTable(
name: "ChatRoomConfig",
columns: table => new
{
RoomKey = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false, comment: "룸 키"),
IsActive = table.Column(type: "bit", nullable: false, comment: "활성 여부 (종목방 단계 오픈 게이트)"),
SlowModeSeconds = table.Column(type: "smallint", nullable: false, comment: "슬로우 모드 (초)"),
Notice = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true, comment: "상단 고정 공지"),
UpdatedAt = table.Column(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChatRoomConfig", x => x.RoomKey);
},
comment: "채팅방 설정 (main | stock:{code})");
migrationBuilder.CreateIndex(
name: "IX_ChatBan_MemberID_ExpiresAt",
table: "ChatBan",
columns: new[] { "MemberID", "ExpiresAt" });
// 메인 채팅방 시드 — 기본 오픈 + 슬로우 모드 3초 (모더레이션 완충 — d2 §⑧)
migrationBuilder.Sql("""
IF NOT EXISTS (SELECT 1 FROM [ChatRoomConfig] WHERE [RoomKey] = N'main')
BEGIN
INSERT INTO [ChatRoomConfig] ([RoomKey], [IsActive], [SlowModeSeconds], [Notice], [UpdatedAt])
VALUES (N'main', 1, 3, NULL, GETUTCDATE());
END
""");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("DELETE FROM [ChatRoomConfig] WHERE [RoomKey] = N'main'");
migrationBuilder.DropTable(
name: "ChatBan");
migrationBuilder.DropTable(
name: "ChatRoomConfig");
}
}
}