| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System;
- using Microsoft.EntityFrameworkCore.Migrations;
- #nullable disable
- #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
- namespace Infrastructure.Migrations.AppDb
- {
- /// <inheritdoc />
- public partial class AddStockDomain : Migration
- {
- /// <inheritdoc />
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "MarketHoliday",
- columns: table => new
- {
- Date = table.Column<DateOnly>(type: "date", nullable: false),
- Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "휴장 사유")
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_MarketHoliday", x => x.Date);
- },
- comment: "KRX 휴장일 (주말 제외, Admin 수동 관리)");
- migrationBuilder.CreateTable(
- name: "Stock",
- columns: table => new
- {
- ID = table.Column<int>(type: "int", nullable: false)
- .Annotation("SqlServer:Identity", "1, 1"),
- Code = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "단축코드"),
- ISIN = table.Column<string>(type: "nchar(12)", fixedLength: true, maxLength: 12, nullable: true, comment: "표준코드"),
- Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
- EnglishName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
- Market = table.Column<byte>(type: "tinyint", nullable: false, comment: "시장 구분 (1=KOSPI, 2=KOSDAQ, 3=KONEX)"),
- TradingStatus = table.Column<byte>(type: "tinyint", nullable: false, comment: "거래 상태 (0=정상, 1=거래정지, 2=관리종목)"),
- CorpCode = table.Column<string>(type: "nchar(8)", fixedLength: true, maxLength: 8, nullable: true, comment: "DART 고유번호"),
- SectorName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
- IsActive = table.Column<bool>(type: "bit", nullable: false),
- ListedDate = table.Column<DateOnly>(type: "date", nullable: false),
- DelistedDate = table.Column<DateOnly>(type: "date", nullable: true),
- LastTradingDate = table.Column<DateOnly>(type: "date", nullable: true),
- LastClosePrice = table.Column<int>(type: "int", nullable: true),
- LastChangeRate = table.Column<decimal>(type: "decimal(7,2)", precision: 7, scale: 2, nullable: true),
- MarketCap = table.Column<long>(type: "bigint", nullable: true),
- CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
- UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Stock", x => x.ID);
- },
- comment: "종목 마스터 (KRX 상장종목)");
- migrationBuilder.CreateTable(
- name: "StockDailyPrice",
- columns: table => new
- {
- ID = table.Column<long>(type: "bigint", nullable: false)
- .Annotation("SqlServer:Identity", "1, 1"),
- StockID = table.Column<int>(type: "int", nullable: false),
- TradingDate = table.Column<DateOnly>(type: "date", nullable: false),
- Open = table.Column<int>(type: "int", nullable: false),
- High = table.Column<int>(type: "int", nullable: false),
- Low = table.Column<int>(type: "int", nullable: false),
- Close = table.Column<int>(type: "int", nullable: false),
- Volume = table.Column<long>(type: "bigint", nullable: false),
- TradingValue = table.Column<long>(type: "bigint", nullable: false),
- ChangeAmount = table.Column<int>(type: "int", nullable: false),
- ChangeRate = table.Column<decimal>(type: "decimal(7,2)", precision: 7, scale: 2, nullable: false, comment: "등락률 %"),
- MarketCap = table.Column<long>(type: "bigint", nullable: true),
- ListedShares = table.Column<long>(type: "bigint", nullable: true),
- CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_StockDailyPrice", x => x.ID);
- table.ForeignKey(
- name: "FK_StockDailyPrice_Stock_StockID",
- column: x => x.StockID,
- principalTable: "Stock",
- principalColumn: "ID");
- },
- comment: "T+1 일별 마감 시세 (금융위 API)");
- migrationBuilder.InsertData(
- table: "MarketHoliday",
- columns: new[] { "Date", "Name" },
- values: new object[,]
- {
- { new DateOnly(2026, 1, 1), "신정" },
- { new DateOnly(2026, 2, 16), "설날 연휴" },
- { new DateOnly(2026, 2, 17), "설날" },
- { new DateOnly(2026, 2, 18), "설날 연휴" },
- { new DateOnly(2026, 3, 2), "삼일절 대체공휴일" },
- { new DateOnly(2026, 5, 5), "어린이날" },
- { new DateOnly(2026, 5, 25), "부처님오신날 대체공휴일" },
- { new DateOnly(2026, 6, 3), "전국동시지방선거" },
- { new DateOnly(2026, 8, 17), "광복절 대체공휴일" },
- { new DateOnly(2026, 9, 24), "추석 연휴" },
- { new DateOnly(2026, 9, 25), "추석" },
- { new DateOnly(2026, 9, 28), "추석 대체공휴일" },
- { new DateOnly(2026, 10, 5), "개천절 대체공휴일" },
- { new DateOnly(2026, 10, 9), "한글날" },
- { new DateOnly(2026, 12, 25), "성탄절" },
- { new DateOnly(2026, 12, 31), "연말 휴장일" }
- });
- migrationBuilder.CreateIndex(
- name: "IX_Stock_Code",
- table: "Stock",
- column: "Code",
- unique: true);
- migrationBuilder.CreateIndex(
- name: "IX_Stock_CorpCode",
- table: "Stock",
- column: "CorpCode");
- migrationBuilder.CreateIndex(
- name: "IX_Stock_ISIN",
- table: "Stock",
- column: "ISIN",
- unique: true,
- filter: "[ISIN] IS NOT NULL");
- migrationBuilder.CreateIndex(
- name: "IX_Stock_Market_IsActive",
- table: "Stock",
- columns: new[] { "Market", "IsActive" });
- migrationBuilder.CreateIndex(
- name: "IX_Stock_Name",
- table: "Stock",
- column: "Name");
- migrationBuilder.CreateIndex(
- name: "IX_StockDailyPrice_StockID_TradingDate",
- table: "StockDailyPrice",
- columns: new[] { "StockID", "TradingDate" },
- unique: true);
- migrationBuilder.CreateIndex(
- name: "IX_StockDailyPrice_TradingDate_ChangeRate",
- table: "StockDailyPrice",
- columns: new[] { "TradingDate", "ChangeRate" },
- descending: new[] { false, true });
- migrationBuilder.CreateIndex(
- name: "IX_StockDailyPrice_TradingDate_TradingValue",
- table: "StockDailyPrice",
- columns: new[] { "TradingDate", "TradingValue" },
- descending: new[] { false, true });
- }
- /// <inheritdoc />
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "MarketHoliday");
- migrationBuilder.DropTable(
- name: "StockDailyPrice");
- migrationBuilder.DropTable(
- name: "Stock");
- }
- }
- }
|