using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations.AppDb;
///
public partial class AddChannelTitlesSystem : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChannelTitle",
columns: table => new
{
ID = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ChannelID = table.Column(type: "int", nullable: false, comment: "채널 ID"),
Name = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false, comment: "칭호 이름"),
Description = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true, comment: "칭호 설명"),
MinAmount = table.Column(type: "bigint", nullable: false, comment: "획득 조건 (누적 후원 최소 금액)"),
Color = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false, comment: "칭호 색상 (hex)"),
IconUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "칭호 아이콘 URL"),
SortOrder = table.Column(type: "int", nullable: false, comment: "정렬 순서"),
IsActive = table.Column(type: "bit", nullable: false, comment: "활성 여부"),
UpdatedAt = table.Column(type: "datetime2", nullable: true, comment: "수정 일시"),
CreatedAt = table.Column(type: "datetime2", nullable: false, comment: "생성 일시")
},
constraints: table =>
{
table.PrimaryKey("PK_ChannelTitle", x => x.ID);
table.ForeignKey(
name: "FK_ChannelTitle_Channel_ChannelID",
column: x => x.ChannelID,
principalTable: "Channel",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
},
comment: "채널별 칭호 (크리에이터 설정)");
migrationBuilder.CreateTable(
name: "DonorChannelStats",
columns: table => new
{
DonorMemberID = table.Column(type: "int", nullable: false, comment: "후원자 회원 ID"),
ChannelID = table.Column(type: "int", nullable: false, comment: "채널 ID"),
CumulativeAmount = table.Column(type: "bigint", nullable: false, comment: "누적 후원 금액"),
DonationCount = table.Column(type: "int", nullable: false, comment: "후원 횟수"),
FirstDonatedAt = table.Column(type: "datetime2", nullable: true, comment: "첫 후원 일시"),
LastDonatedAt = table.Column(type: "datetime2", nullable: true, comment: "마지막 후원 일시"),
UpdatedAt = table.Column(type: "datetime2", nullable: true, comment: "수정 일시"),
CreatedAt = table.Column(type: "datetime2", nullable: false, comment: "생성 일시")
},
constraints: table =>
{
table.PrimaryKey("PK_DonorChannelStats", x => new { x.DonorMemberID, x.ChannelID });
table.ForeignKey(
name: "FK_DonorChannelStats_Channel_ChannelID",
column: x => x.ChannelID,
principalTable: "Channel",
principalColumn: "ID");
table.ForeignKey(
name: "FK_DonorChannelStats_Member_DonorMemberID",
column: x => x.DonorMemberID,
principalTable: "Member",
principalColumn: "ID");
},
comment: "후원자×채널 누적 후원 (칭호 획득 판정용)");
migrationBuilder.CreateTable(
name: "DonorTitleSelection",
columns: table => new
{
ID = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DonorMemberID = table.Column(type: "int", nullable: false, comment: "후원자 회원 ID"),
ChannelID = table.Column(type: "int", nullable: false, comment: "채널 ID"),
SelectedTitleID = table.Column(type: "int", nullable: true, comment: "선택 칭호 ID"),
UpdatedAt = table.Column(type: "datetime2", nullable: true, comment: "수정 일시"),
CreatedAt = table.Column(type: "datetime2", nullable: false, comment: "생성 일시")
},
constraints: table =>
{
table.PrimaryKey("PK_DonorTitleSelection", x => x.ID);
table.ForeignKey(
name: "FK_DonorTitleSelection_ChannelTitle_SelectedTitleID",
column: x => x.SelectedTitleID,
principalTable: "ChannelTitle",
principalColumn: "ID",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_DonorTitleSelection_Channel_ChannelID",
column: x => x.ChannelID,
principalTable: "Channel",
principalColumn: "ID");
table.ForeignKey(
name: "FK_DonorTitleSelection_Member_DonorMemberID",
column: x => x.DonorMemberID,
principalTable: "Member",
principalColumn: "ID");
},
comment: "후원자가 선택한 채널별 대표 칭호");
migrationBuilder.CreateIndex(
name: "IX_ChannelTitle_ChannelID_MinAmount",
table: "ChannelTitle",
columns: new[] { "ChannelID", "MinAmount" });
migrationBuilder.CreateIndex(
name: "IX_ChannelTitle_ChannelID_SortOrder",
table: "ChannelTitle",
columns: new[] { "ChannelID", "SortOrder" });
migrationBuilder.CreateIndex(
name: "IX_DonorChannelStats_ChannelID_CumulativeAmount",
table: "DonorChannelStats",
columns: new[] { "ChannelID", "CumulativeAmount" },
descending: new[] { false, true });
migrationBuilder.CreateIndex(
name: "IX_DonorTitleSelection_ChannelID",
table: "DonorTitleSelection",
column: "ChannelID");
migrationBuilder.CreateIndex(
name: "IX_DonorTitleSelection_DonorMemberID_ChannelID",
table: "DonorTitleSelection",
columns: new[] { "DonorMemberID", "ChannelID" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_DonorTitleSelection_SelectedTitleID",
table: "DonorTitleSelection",
column: "SelectedTitleID");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DonorChannelStats");
migrationBuilder.DropTable(
name: "DonorTitleSelection");
migrationBuilder.DropTable(
name: "ChannelTitle");
}
}