20260706050821_AddCommodityDailyTrade.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddCommodityDailyTrade : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.CreateTable(
  13. name: "CommodityDailyTrade",
  14. columns: table => new
  15. {
  16. ID = table.Column<long>(type: "bigint", nullable: false)
  17. .Annotation("SqlServer:Identity", "1, 1"),
  18. CommodityMarket = table.Column<byte>(type: "tinyint", nullable: false, comment: "일반상품 시장 구분 (1=석유, 2=금, 3=배출권)"),
  19. Code = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false, comment: "단축코드 (ISU_CD) — 석유는 OIL_NM(유종구분)"),
  20. Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "종목명 (ISU_NM) — 석유는 유종구분"),
  21. TradeDate = table.Column<DateOnly>(type: "date", nullable: false),
  22. Close = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "종가 (TDD_CLSPRC) — 석유는 가중평균가격_경쟁"),
  23. Open = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "시가 (TDD_OPNPRC) — 석유 0"),
  24. High = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "고가 (TDD_HGPRC) — 석유 0"),
  25. Low = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "저가 (TDD_LWPRC) — 석유 0"),
  26. ChangeAmount = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "전일 대비 (CMPPREVDD_PRC) — 금/배출권만"),
  27. ChangeRate = table.Column<decimal>(type: "decimal(9,2)", precision: 9, scale: 2, nullable: true, comment: "등락률 % (FLUC_RT) — 금/배출권만"),
  28. WeightedDiscussionPrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "가중평균가격_협의 (WT_DIS_AVG_PRC) — 석유만"),
  29. Volume = table.Column<long>(type: "bigint", nullable: false, comment: "거래량 (ACC_TRDVOL)"),
  30. TradeValue = table.Column<long>(type: "bigint", nullable: false, comment: "거래대금 (ACC_TRDVAL, 원)"),
  31. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  32. },
  33. constraints: table =>
  34. {
  35. table.PrimaryKey("PK_CommodityDailyTrade", x => x.ID);
  36. },
  37. comment: "일반상품(석유/금/배출권) 일별매매 시세 (KRX OpenAPI gen)");
  38. migrationBuilder.CreateIndex(
  39. name: "IX_CommodityDailyTrade_CommodityMarket_Code_TradeDate",
  40. table: "CommodityDailyTrade",
  41. columns: new[] { "CommodityMarket", "Code", "TradeDate" },
  42. unique: true);
  43. migrationBuilder.CreateIndex(
  44. name: "IX_CommodityDailyTrade_CommodityMarket_TradeDate_TradeValue",
  45. table: "CommodityDailyTrade",
  46. columns: new[] { "CommodityMarket", "TradeDate", "TradeValue" },
  47. descending: new[] { false, false, true });
  48. }
  49. /// <inheritdoc />
  50. protected override void Down(MigrationBuilder migrationBuilder)
  51. {
  52. migrationBuilder.DropTable(
  53. name: "CommodityDailyTrade");
  54. }
  55. }
  56. }