20260706032311_AddStockBoard.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddStockBoard : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.AddColumn<string>(
  13. name: "StockCode",
  14. table: "Post",
  15. type: "nchar(6)",
  16. fixedLength: true,
  17. maxLength: 6,
  18. nullable: true,
  19. comment: "종목 가상보드 파티션 코드 (stock 보드 전용)");
  20. migrationBuilder.CreateTable(
  21. name: "PostPrediction",
  22. columns: table => new
  23. {
  24. ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
  25. .Annotation("SqlServer:Identity", "1, 1"),
  26. PostID = table.Column<int>(type: "int", nullable: false, comment: "게시글 ID (1:1)"),
  27. MemberID = table.Column<int>(type: "int", nullable: false, comment: "작성 회원 ID"),
  28. StockCode = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "예측 종목 단축코드"),
  29. Direction = table.Column<byte>(type: "tinyint", nullable: false, comment: "예측 방향 (1=상승, 2=하락)"),
  30. BasePrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "작성 시점 기준가"),
  31. TargetPrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "목표가 (선택)"),
  32. HorizonDays = table.Column<short>(type: "smallint", nullable: false, comment: "예측 기간 (영업일 수)"),
  33. DueDate = table.Column<DateOnly>(type: "date", nullable: false, comment: "채점 예정일"),
  34. Status = table.Column<byte>(type: "tinyint", nullable: false, comment: "상태 (0=Pending/1=Hit/2=Miss/3=Void)"),
  35. SettledPrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "채점 시점 종가"),
  36. SettledAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "채점 일시"),
  37. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "등록 일시")
  38. },
  39. constraints: table =>
  40. {
  41. table.PrimaryKey("PK_PostPrediction", x => x.ID);
  42. table.ForeignKey(
  43. name: "FK_PostPrediction_Member_MemberID",
  44. column: x => x.MemberID,
  45. principalTable: "Member",
  46. principalColumn: "ID",
  47. onDelete: ReferentialAction.Restrict);
  48. table.ForeignKey(
  49. name: "FK_PostPrediction_Post_PostID",
  50. column: x => x.PostID,
  51. principalTable: "Post",
  52. principalColumn: "ID",
  53. onDelete: ReferentialAction.Cascade);
  54. },
  55. comment: "예측글 (방향/기간 예측 + 채점)");
  56. migrationBuilder.CreateTable(
  57. name: "PostStockTag",
  58. columns: table => new
  59. {
  60. ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
  61. .Annotation("SqlServer:Identity", "1, 1"),
  62. PostID = table.Column<int>(type: "int", nullable: false, comment: "게시글 ID"),
  63. StockCode = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "종목 단축코드"),
  64. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "등록 일시")
  65. },
  66. constraints: table =>
  67. {
  68. table.PrimaryKey("PK_PostStockTag", x => x.ID);
  69. table.ForeignKey(
  70. name: "FK_PostStockTag_Post_PostID",
  71. column: x => x.PostID,
  72. principalTable: "Post",
  73. principalColumn: "ID",
  74. onDelete: ReferentialAction.Cascade);
  75. },
  76. comment: "글 본문 $종목 태그 (언급량 랭킹 원천)");
  77. migrationBuilder.CreateTable(
  78. name: "StockBoardStats",
  79. columns: table => new
  80. {
  81. StockCode = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "종목 단축코드 (PK)"),
  82. Posts = table.Column<int>(type: "int", nullable: false, comment: "게시글 수"),
  83. Comments = table.Column<int>(type: "int", nullable: false, comment: "댓글 수"),
  84. LastPostAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "마지막 글 작성 일시"),
  85. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "갱신 일시")
  86. },
  87. constraints: table =>
  88. {
  89. table.PrimaryKey("PK_StockBoardStats", x => x.StockCode);
  90. },
  91. comment: "종목 가상보드 통계 (글/댓글 수)");
  92. migrationBuilder.CreateIndex(
  93. name: "IX_Post_StockCode_CreatedAt",
  94. table: "Post",
  95. columns: new[] { "StockCode", "CreatedAt" },
  96. descending: new[] { false, true },
  97. filter: "[StockCode] IS NOT NULL AND [IsDeleted] = 0");
  98. migrationBuilder.CreateIndex(
  99. name: "IX_PostPrediction_MemberID_Status",
  100. table: "PostPrediction",
  101. columns: new[] { "MemberID", "Status" });
  102. migrationBuilder.CreateIndex(
  103. name: "IX_PostPrediction_PostID",
  104. table: "PostPrediction",
  105. column: "PostID",
  106. unique: true);
  107. migrationBuilder.CreateIndex(
  108. name: "IX_PostPrediction_Status_DueDate",
  109. table: "PostPrediction",
  110. columns: new[] { "Status", "DueDate" });
  111. migrationBuilder.CreateIndex(
  112. name: "IX_PostStockTag_PostID_StockCode",
  113. table: "PostStockTag",
  114. columns: new[] { "PostID", "StockCode" },
  115. unique: true);
  116. migrationBuilder.CreateIndex(
  117. name: "IX_PostStockTag_StockCode_CreatedAt",
  118. table: "PostStockTag",
  119. columns: new[] { "StockCode", "CreatedAt" },
  120. descending: new[] { false, true });
  121. }
  122. /// <inheritdoc />
  123. protected override void Down(MigrationBuilder migrationBuilder)
  124. {
  125. migrationBuilder.DropTable(
  126. name: "PostPrediction");
  127. migrationBuilder.DropTable(
  128. name: "PostStockTag");
  129. migrationBuilder.DropTable(
  130. name: "StockBoardStats");
  131. migrationBuilder.DropIndex(
  132. name: "IX_Post_StockCode_CreatedAt",
  133. table: "Post");
  134. migrationBuilder.DropColumn(
  135. name: "StockCode",
  136. table: "Post");
  137. }
  138. }
  139. }