using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional namespace Infrastructure.Migrations.AppDb { /// public partial class AddStockDomain : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "MarketHoliday", columns: table => new { Date = table.Column(type: "date", nullable: false), Name = table.Column(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(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Code = table.Column(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "단축코드"), ISIN = table.Column(type: "nchar(12)", fixedLength: true, maxLength: 12, nullable: true, comment: "표준코드"), Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), EnglishName = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), Market = table.Column(type: "tinyint", nullable: false, comment: "시장 구분 (1=KOSPI, 2=KOSDAQ, 3=KONEX)"), TradingStatus = table.Column(type: "tinyint", nullable: false, comment: "거래 상태 (0=정상, 1=거래정지, 2=관리종목)"), CorpCode = table.Column(type: "nchar(8)", fixedLength: true, maxLength: 8, nullable: true, comment: "DART 고유번호"), SectorName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), IsActive = table.Column(type: "bit", nullable: false), ListedDate = table.Column(type: "date", nullable: false), DelistedDate = table.Column(type: "date", nullable: true), LastTradingDate = table.Column(type: "date", nullable: true), LastClosePrice = table.Column(type: "int", nullable: true), LastChangeRate = table.Column(type: "decimal(7,2)", precision: 7, scale: 2, nullable: true), MarketCap = table.Column(type: "bigint", nullable: true), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(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(type: "bigint", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), StockID = table.Column(type: "int", nullable: false), TradingDate = table.Column(type: "date", nullable: false), Open = table.Column(type: "int", nullable: false), High = table.Column(type: "int", nullable: false), Low = table.Column(type: "int", nullable: false), Close = table.Column(type: "int", nullable: false), Volume = table.Column(type: "bigint", nullable: false), TradingValue = table.Column(type: "bigint", nullable: false), ChangeAmount = table.Column(type: "int", nullable: false), ChangeRate = table.Column(type: "decimal(7,2)", precision: 7, scale: 2, nullable: false, comment: "등락률 %"), MarketCap = table.Column(type: "bigint", nullable: true), ListedShares = table.Column(type: "bigint", nullable: true), CreatedAt = table.Column(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 }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "MarketHoliday"); migrationBuilder.DropTable( name: "StockDailyPrice"); migrationBuilder.DropTable( name: "Stock"); } } }