| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using Microsoft.EntityFrameworkCore.Migrations;
- #nullable disable
- namespace Infrastructure.Migrations.AppDb
- {
- /// <inheritdoc />
- public partial class AddStockBoard : Migration
- {
- /// <inheritdoc />
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AddColumn<string>(
- name: "StockCode",
- table: "Post",
- type: "nchar(6)",
- fixedLength: true,
- maxLength: 6,
- nullable: true,
- comment: "종목 가상보드 파티션 코드 (stock 보드 전용)");
- migrationBuilder.CreateTable(
- name: "PostPrediction",
- columns: table => new
- {
- ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
- .Annotation("SqlServer:Identity", "1, 1"),
- PostID = table.Column<int>(type: "int", nullable: false, comment: "게시글 ID (1:1)"),
- MemberID = table.Column<int>(type: "int", nullable: false, comment: "작성 회원 ID"),
- StockCode = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "예측 종목 단축코드"),
- Direction = table.Column<byte>(type: "tinyint", nullable: false, comment: "예측 방향 (1=상승, 2=하락)"),
- BasePrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "작성 시점 기준가"),
- TargetPrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "목표가 (선택)"),
- HorizonDays = table.Column<short>(type: "smallint", nullable: false, comment: "예측 기간 (영업일 수)"),
- DueDate = table.Column<DateOnly>(type: "date", nullable: false, comment: "채점 예정일"),
- Status = table.Column<byte>(type: "tinyint", nullable: false, comment: "상태 (0=Pending/1=Hit/2=Miss/3=Void)"),
- SettledPrice = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "채점 시점 종가"),
- SettledAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "채점 일시"),
- CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "등록 일시")
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_PostPrediction", x => x.ID);
- table.ForeignKey(
- name: "FK_PostPrediction_Member_MemberID",
- column: x => x.MemberID,
- principalTable: "Member",
- principalColumn: "ID",
- onDelete: ReferentialAction.Restrict);
- table.ForeignKey(
- name: "FK_PostPrediction_Post_PostID",
- column: x => x.PostID,
- principalTable: "Post",
- principalColumn: "ID",
- onDelete: ReferentialAction.Cascade);
- },
- comment: "예측글 (방향/기간 예측 + 채점)");
- migrationBuilder.CreateTable(
- name: "PostStockTag",
- columns: table => new
- {
- ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
- .Annotation("SqlServer:Identity", "1, 1"),
- PostID = table.Column<int>(type: "int", nullable: false, comment: "게시글 ID"),
- StockCode = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "종목 단축코드"),
- CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "등록 일시")
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_PostStockTag", x => x.ID);
- table.ForeignKey(
- name: "FK_PostStockTag_Post_PostID",
- column: x => x.PostID,
- principalTable: "Post",
- principalColumn: "ID",
- onDelete: ReferentialAction.Cascade);
- },
- comment: "글 본문 $종목 태그 (언급량 랭킹 원천)");
- migrationBuilder.CreateTable(
- name: "StockBoardStats",
- columns: table => new
- {
- StockCode = table.Column<string>(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "종목 단축코드 (PK)"),
- Posts = table.Column<int>(type: "int", nullable: false, comment: "게시글 수"),
- Comments = table.Column<int>(type: "int", nullable: false, comment: "댓글 수"),
- LastPostAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "마지막 글 작성 일시"),
- UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "갱신 일시")
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_StockBoardStats", x => x.StockCode);
- },
- comment: "종목 가상보드 통계 (글/댓글 수)");
- migrationBuilder.CreateIndex(
- name: "IX_Post_StockCode_CreatedAt",
- table: "Post",
- columns: new[] { "StockCode", "CreatedAt" },
- descending: new[] { false, true },
- filter: "[StockCode] IS NOT NULL AND [IsDeleted] = 0");
- migrationBuilder.CreateIndex(
- name: "IX_PostPrediction_MemberID_Status",
- table: "PostPrediction",
- columns: new[] { "MemberID", "Status" });
- migrationBuilder.CreateIndex(
- name: "IX_PostPrediction_PostID",
- table: "PostPrediction",
- column: "PostID",
- unique: true);
- migrationBuilder.CreateIndex(
- name: "IX_PostPrediction_Status_DueDate",
- table: "PostPrediction",
- columns: new[] { "Status", "DueDate" });
- migrationBuilder.CreateIndex(
- name: "IX_PostStockTag_PostID_StockCode",
- table: "PostStockTag",
- columns: new[] { "PostID", "StockCode" },
- unique: true);
- migrationBuilder.CreateIndex(
- name: "IX_PostStockTag_StockCode_CreatedAt",
- table: "PostStockTag",
- columns: new[] { "StockCode", "CreatedAt" },
- descending: new[] { false, true });
- }
- /// <inheritdoc />
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "PostPrediction");
- migrationBuilder.DropTable(
- name: "PostStockTag");
- migrationBuilder.DropTable(
- name: "StockBoardStats");
- migrationBuilder.DropIndex(
- name: "IX_Post_StockCode_CreatedAt",
- table: "Post");
- migrationBuilder.DropColumn(
- name: "StockCode",
- table: "Post");
- }
- }
- }
|