20260417001816_AddChannelTitlesSystem.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb;
  5. /// <inheritdoc />
  6. public partial class AddChannelTitlesSystem : Migration
  7. {
  8. /// <inheritdoc />
  9. protected override void Up(MigrationBuilder migrationBuilder)
  10. {
  11. migrationBuilder.CreateTable(
  12. name: "ChannelTitle",
  13. columns: table => new
  14. {
  15. ID = table.Column<int>(type: "int", nullable: false)
  16. .Annotation("SqlServer:Identity", "1, 1"),
  17. ChannelID = table.Column<int>(type: "int", nullable: false, comment: "채널 ID"),
  18. Name = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false, comment: "칭호 이름"),
  19. Description = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true, comment: "칭호 설명"),
  20. MinAmount = table.Column<long>(type: "bigint", nullable: false, comment: "획득 조건 (누적 후원 최소 금액)"),
  21. Color = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false, comment: "칭호 색상 (hex)"),
  22. IconUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "칭호 아이콘 URL"),
  23. SortOrder = table.Column<int>(type: "int", nullable: false, comment: "정렬 순서"),
  24. IsActive = table.Column<bool>(type: "bit", nullable: false, comment: "활성 여부"),
  25. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "수정 일시"),
  26. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "생성 일시")
  27. },
  28. constraints: table =>
  29. {
  30. table.PrimaryKey("PK_ChannelTitle", x => x.ID);
  31. table.ForeignKey(
  32. name: "FK_ChannelTitle_Channel_ChannelID",
  33. column: x => x.ChannelID,
  34. principalTable: "Channel",
  35. principalColumn: "ID",
  36. onDelete: ReferentialAction.Cascade);
  37. },
  38. comment: "채널별 칭호 (크리에이터 설정)");
  39. migrationBuilder.CreateTable(
  40. name: "DonorChannelStats",
  41. columns: table => new
  42. {
  43. DonorMemberID = table.Column<int>(type: "int", nullable: false, comment: "후원자 회원 ID"),
  44. ChannelID = table.Column<int>(type: "int", nullable: false, comment: "채널 ID"),
  45. CumulativeAmount = table.Column<long>(type: "bigint", nullable: false, comment: "누적 후원 금액"),
  46. DonationCount = table.Column<int>(type: "int", nullable: false, comment: "후원 횟수"),
  47. FirstDonatedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "첫 후원 일시"),
  48. LastDonatedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "마지막 후원 일시"),
  49. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "수정 일시"),
  50. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "생성 일시")
  51. },
  52. constraints: table =>
  53. {
  54. table.PrimaryKey("PK_DonorChannelStats", x => new { x.DonorMemberID, x.ChannelID });
  55. table.ForeignKey(
  56. name: "FK_DonorChannelStats_Channel_ChannelID",
  57. column: x => x.ChannelID,
  58. principalTable: "Channel",
  59. principalColumn: "ID");
  60. table.ForeignKey(
  61. name: "FK_DonorChannelStats_Member_DonorMemberID",
  62. column: x => x.DonorMemberID,
  63. principalTable: "Member",
  64. principalColumn: "ID");
  65. },
  66. comment: "후원자×채널 누적 후원 (칭호 획득 판정용)");
  67. migrationBuilder.CreateTable(
  68. name: "DonorTitleSelection",
  69. columns: table => new
  70. {
  71. ID = table.Column<int>(type: "int", nullable: false)
  72. .Annotation("SqlServer:Identity", "1, 1"),
  73. DonorMemberID = table.Column<int>(type: "int", nullable: false, comment: "후원자 회원 ID"),
  74. ChannelID = table.Column<int>(type: "int", nullable: false, comment: "채널 ID"),
  75. SelectedTitleID = table.Column<int>(type: "int", nullable: true, comment: "선택 칭호 ID"),
  76. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "수정 일시"),
  77. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "생성 일시")
  78. },
  79. constraints: table =>
  80. {
  81. table.PrimaryKey("PK_DonorTitleSelection", x => x.ID);
  82. table.ForeignKey(
  83. name: "FK_DonorTitleSelection_ChannelTitle_SelectedTitleID",
  84. column: x => x.SelectedTitleID,
  85. principalTable: "ChannelTitle",
  86. principalColumn: "ID",
  87. onDelete: ReferentialAction.SetNull);
  88. table.ForeignKey(
  89. name: "FK_DonorTitleSelection_Channel_ChannelID",
  90. column: x => x.ChannelID,
  91. principalTable: "Channel",
  92. principalColumn: "ID");
  93. table.ForeignKey(
  94. name: "FK_DonorTitleSelection_Member_DonorMemberID",
  95. column: x => x.DonorMemberID,
  96. principalTable: "Member",
  97. principalColumn: "ID");
  98. },
  99. comment: "후원자가 선택한 채널별 대표 칭호");
  100. migrationBuilder.CreateIndex(
  101. name: "IX_ChannelTitle_ChannelID_MinAmount",
  102. table: "ChannelTitle",
  103. columns: new[] { "ChannelID", "MinAmount" });
  104. migrationBuilder.CreateIndex(
  105. name: "IX_ChannelTitle_ChannelID_SortOrder",
  106. table: "ChannelTitle",
  107. columns: new[] { "ChannelID", "SortOrder" });
  108. migrationBuilder.CreateIndex(
  109. name: "IX_DonorChannelStats_ChannelID_CumulativeAmount",
  110. table: "DonorChannelStats",
  111. columns: new[] { "ChannelID", "CumulativeAmount" },
  112. descending: new[] { false, true });
  113. migrationBuilder.CreateIndex(
  114. name: "IX_DonorTitleSelection_ChannelID",
  115. table: "DonorTitleSelection",
  116. column: "ChannelID");
  117. migrationBuilder.CreateIndex(
  118. name: "IX_DonorTitleSelection_DonorMemberID_ChannelID",
  119. table: "DonorTitleSelection",
  120. columns: new[] { "DonorMemberID", "ChannelID" },
  121. unique: true);
  122. migrationBuilder.CreateIndex(
  123. name: "IX_DonorTitleSelection_SelectedTitleID",
  124. table: "DonorTitleSelection",
  125. column: "SelectedTitleID");
  126. }
  127. /// <inheritdoc />
  128. protected override void Down(MigrationBuilder migrationBuilder)
  129. {
  130. migrationBuilder.DropTable(
  131. name: "DonorChannelStats");
  132. migrationBuilder.DropTable(
  133. name: "DonorTitleSelection");
  134. migrationBuilder.DropTable(
  135. name: "ChannelTitle");
  136. }
  137. }