using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations.AppDb
{
///
public partial class AddStockBoard : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn(
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(type: "int", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
PostID = table.Column(type: "int", nullable: false, comment: "게시글 ID (1:1)"),
MemberID = table.Column(type: "int", nullable: false, comment: "작성 회원 ID"),
StockCode = table.Column(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "예측 종목 단축코드"),
Direction = table.Column(type: "tinyint", nullable: false, comment: "예측 방향 (1=상승, 2=하락)"),
BasePrice = table.Column(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false, comment: "작성 시점 기준가"),
TargetPrice = table.Column(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "목표가 (선택)"),
HorizonDays = table.Column(type: "smallint", nullable: false, comment: "예측 기간 (영업일 수)"),
DueDate = table.Column(type: "date", nullable: false, comment: "채점 예정일"),
Status = table.Column(type: "tinyint", nullable: false, comment: "상태 (0=Pending/1=Hit/2=Miss/3=Void)"),
SettledPrice = table.Column(type: "decimal(18,2)", precision: 18, scale: 2, nullable: true, comment: "채점 시점 종가"),
SettledAt = table.Column(type: "datetime2", nullable: true, comment: "채점 일시"),
CreatedAt = table.Column(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(type: "int", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
PostID = table.Column(type: "int", nullable: false, comment: "게시글 ID"),
StockCode = table.Column(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "종목 단축코드"),
CreatedAt = table.Column(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(type: "nchar(6)", fixedLength: true, maxLength: 6, nullable: false, comment: "종목 단축코드 (PK)"),
Posts = table.Column(type: "int", nullable: false, comment: "게시글 수"),
Comments = table.Column(type: "int", nullable: false, comment: "댓글 수"),
LastPostAt = table.Column(type: "datetime2", nullable: true, comment: "마지막 글 작성 일시"),
UpdatedAt = table.Column(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 });
}
///
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");
}
}
}