20260703014156_AddStockDomain.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
  5. namespace Infrastructure.Migrations.AppDb
  6. {
  7. /// <inheritdoc />
  8. public partial class AddStockDomain : Migration
  9. {
  10. /// <inheritdoc />
  11. protected override void Up(MigrationBuilder migrationBuilder)
  12. {
  13. migrationBuilder.CreateTable(
  14. name: "MarketHoliday",
  15. columns: table => new
  16. {
  17. Date = table.Column<DateOnly>(type: "date", nullable: false),
  18. Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "휴장 사유")
  19. },
  20. constraints: table =>
  21. {
  22. table.PrimaryKey("PK_MarketHoliday", x => x.Date);
  23. },
  24. comment: "KRX 휴장일 (주말 제외, Admin 수동 관리)");
  25. migrationBuilder.CreateTable(
  26. name: "Stock",
  27. columns: table => new
  28. {
  29. ID = table.Column<int>(type: "int", nullable: false)
  30. .Annotation("SqlServer:Identity", "1, 1"),
  31. Code = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "단축코드"),
  32. ISIN = table.Column<string>(type: "nchar(12)", fixedLength: true, maxLength: 12, nullable: true, comment: "표준코드"),
  33. Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
  34. EnglishName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
  35. Market = table.Column<byte>(type: "tinyint", nullable: false, comment: "시장 구분 (1=KOSPI, 2=KOSDAQ, 3=KONEX)"),
  36. TradingStatus = table.Column<byte>(type: "tinyint", nullable: false, comment: "거래 상태 (0=정상, 1=거래정지, 2=관리종목)"),
  37. CorpCode = table.Column<string>(type: "nchar(8)", fixedLength: true, maxLength: 8, nullable: true, comment: "DART 고유번호"),
  38. SectorName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
  39. IsActive = table.Column<bool>(type: "bit", nullable: false),
  40. ListedDate = table.Column<DateOnly>(type: "date", nullable: false),
  41. DelistedDate = table.Column<DateOnly>(type: "date", nullable: true),
  42. LastTradingDate = table.Column<DateOnly>(type: "date", nullable: true),
  43. LastClosePrice = table.Column<int>(type: "int", nullable: true),
  44. LastChangeRate = table.Column<decimal>(type: "decimal(7,2)", precision: 7, scale: 2, nullable: true),
  45. MarketCap = table.Column<long>(type: "bigint", nullable: true),
  46. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  47. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
  48. },
  49. constraints: table =>
  50. {
  51. table.PrimaryKey("PK_Stock", x => x.ID);
  52. },
  53. comment: "종목 마스터 (KRX 상장종목)");
  54. migrationBuilder.CreateTable(
  55. name: "StockDailyPrice",
  56. columns: table => new
  57. {
  58. ID = table.Column<long>(type: "bigint", nullable: false)
  59. .Annotation("SqlServer:Identity", "1, 1"),
  60. StockID = table.Column<int>(type: "int", nullable: false),
  61. TradingDate = table.Column<DateOnly>(type: "date", nullable: false),
  62. Open = table.Column<int>(type: "int", nullable: false),
  63. High = table.Column<int>(type: "int", nullable: false),
  64. Low = table.Column<int>(type: "int", nullable: false),
  65. Close = table.Column<int>(type: "int", nullable: false),
  66. Volume = table.Column<long>(type: "bigint", nullable: false),
  67. TradingValue = table.Column<long>(type: "bigint", nullable: false),
  68. ChangeAmount = table.Column<int>(type: "int", nullable: false),
  69. ChangeRate = table.Column<decimal>(type: "decimal(7,2)", precision: 7, scale: 2, nullable: false, comment: "등락률 %"),
  70. MarketCap = table.Column<long>(type: "bigint", nullable: true),
  71. ListedShares = table.Column<long>(type: "bigint", nullable: true),
  72. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  73. },
  74. constraints: table =>
  75. {
  76. table.PrimaryKey("PK_StockDailyPrice", x => x.ID);
  77. table.ForeignKey(
  78. name: "FK_StockDailyPrice_Stock_StockID",
  79. column: x => x.StockID,
  80. principalTable: "Stock",
  81. principalColumn: "ID");
  82. },
  83. comment: "T+1 일별 마감 시세 (금융위 API)");
  84. migrationBuilder.InsertData(
  85. table: "MarketHoliday",
  86. columns: new[] { "Date", "Name" },
  87. values: new object[,]
  88. {
  89. { new DateOnly(2026, 1, 1), "신정" },
  90. { new DateOnly(2026, 2, 16), "설날 연휴" },
  91. { new DateOnly(2026, 2, 17), "설날" },
  92. { new DateOnly(2026, 2, 18), "설날 연휴" },
  93. { new DateOnly(2026, 3, 2), "삼일절 대체공휴일" },
  94. { new DateOnly(2026, 5, 5), "어린이날" },
  95. { new DateOnly(2026, 5, 25), "부처님오신날 대체공휴일" },
  96. { new DateOnly(2026, 6, 3), "전국동시지방선거" },
  97. { new DateOnly(2026, 8, 17), "광복절 대체공휴일" },
  98. { new DateOnly(2026, 9, 24), "추석 연휴" },
  99. { new DateOnly(2026, 9, 25), "추석" },
  100. { new DateOnly(2026, 9, 28), "추석 대체공휴일" },
  101. { new DateOnly(2026, 10, 5), "개천절 대체공휴일" },
  102. { new DateOnly(2026, 10, 9), "한글날" },
  103. { new DateOnly(2026, 12, 25), "성탄절" },
  104. { new DateOnly(2026, 12, 31), "연말 휴장일" }
  105. });
  106. migrationBuilder.CreateIndex(
  107. name: "IX_Stock_Code",
  108. table: "Stock",
  109. column: "Code",
  110. unique: true);
  111. migrationBuilder.CreateIndex(
  112. name: "IX_Stock_CorpCode",
  113. table: "Stock",
  114. column: "CorpCode");
  115. migrationBuilder.CreateIndex(
  116. name: "IX_Stock_ISIN",
  117. table: "Stock",
  118. column: "ISIN",
  119. unique: true,
  120. filter: "[ISIN] IS NOT NULL");
  121. migrationBuilder.CreateIndex(
  122. name: "IX_Stock_Market_IsActive",
  123. table: "Stock",
  124. columns: new[] { "Market", "IsActive" });
  125. migrationBuilder.CreateIndex(
  126. name: "IX_Stock_Name",
  127. table: "Stock",
  128. column: "Name");
  129. migrationBuilder.CreateIndex(
  130. name: "IX_StockDailyPrice_StockID_TradingDate",
  131. table: "StockDailyPrice",
  132. columns: new[] { "StockID", "TradingDate" },
  133. unique: true);
  134. migrationBuilder.CreateIndex(
  135. name: "IX_StockDailyPrice_TradingDate_ChangeRate",
  136. table: "StockDailyPrice",
  137. columns: new[] { "TradingDate", "ChangeRate" },
  138. descending: new[] { false, true });
  139. migrationBuilder.CreateIndex(
  140. name: "IX_StockDailyPrice_TradingDate_TradingValue",
  141. table: "StockDailyPrice",
  142. columns: new[] { "TradingDate", "TradingValue" },
  143. descending: new[] { false, true });
  144. }
  145. /// <inheritdoc />
  146. protected override void Down(MigrationBuilder migrationBuilder)
  147. {
  148. migrationBuilder.DropTable(
  149. name: "MarketHoliday");
  150. migrationBuilder.DropTable(
  151. name: "StockDailyPrice");
  152. migrationBuilder.DropTable(
  153. name: "Stock");
  154. }
  155. }
  156. }