20260703020029_AddChatRoomDomain.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddChatRoomDomain : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.CreateTable(
  13. name: "ChatBan",
  14. columns: table => new
  15. {
  16. ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
  17. .Annotation("SqlServer:Identity", "1, 1"),
  18. MemberID = table.Column<int>(type: "int", nullable: false, comment: "제재 대상 회원 ID"),
  19. RoomKey = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true, comment: "제재 룸 키 (NULL=전체)"),
  20. Reason = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false, comment: "제재 사유"),
  21. ExpiresAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  22. CreatedBy = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "제재 등록자"),
  23. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  24. },
  25. constraints: table =>
  26. {
  27. table.PrimaryKey("PK_ChatBan", x => x.ID);
  28. table.ForeignKey(
  29. name: "FK_ChatBan_Member_MemberID",
  30. column: x => x.MemberID,
  31. principalTable: "Member",
  32. principalColumn: "ID",
  33. onDelete: ReferentialAction.Restrict);
  34. },
  35. comment: "채팅 제재 (RoomKey NULL=전체, ExpiresAt NULL=무기한)");
  36. migrationBuilder.CreateTable(
  37. name: "ChatRoomConfig",
  38. columns: table => new
  39. {
  40. RoomKey = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false, comment: "룸 키"),
  41. IsActive = table.Column<bool>(type: "bit", nullable: false, comment: "활성 여부 (종목방 단계 오픈 게이트)"),
  42. SlowModeSeconds = table.Column<short>(type: "smallint", nullable: false, comment: "슬로우 모드 (초)"),
  43. Notice = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true, comment: "상단 고정 공지"),
  44. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  45. },
  46. constraints: table =>
  47. {
  48. table.PrimaryKey("PK_ChatRoomConfig", x => x.RoomKey);
  49. },
  50. comment: "채팅방 설정 (main | stock:{code})");
  51. migrationBuilder.CreateIndex(
  52. name: "IX_ChatBan_MemberID_ExpiresAt",
  53. table: "ChatBan",
  54. columns: new[] { "MemberID", "ExpiresAt" });
  55. // 메인 채팅방 시드 — 기본 오픈 + 슬로우 모드 3초 (모더레이션 완충 — d2 §⑧)
  56. migrationBuilder.Sql("""
  57. IF NOT EXISTS (SELECT 1 FROM [ChatRoomConfig] WHERE [RoomKey] = N'main')
  58. BEGIN
  59. INSERT INTO [ChatRoomConfig] ([RoomKey], [IsActive], [SlowModeSeconds], [Notice], [UpdatedAt])
  60. VALUES (N'main', 1, 3, NULL, GETUTCDATE());
  61. END
  62. """);
  63. }
  64. /// <inheritdoc />
  65. protected override void Down(MigrationBuilder migrationBuilder)
  66. {
  67. migrationBuilder.Sql("DELETE FROM [ChatRoomConfig] WHERE [RoomKey] = N'main'");
  68. migrationBuilder.DropTable(
  69. name: "ChatBan");
  70. migrationBuilder.DropTable(
  71. name: "ChatRoomConfig");
  72. }
  73. }
  74. }