using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddDonation : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterTable(
                name: "Channel",
                comment: "ä�� ����",
                oldComment: "채널 정보");

            migrationBuilder.AlterColumn<string>(
                name: "YouTubeUrl",
                table: "Channel",
                type: "nvarchar(255)",
                maxLength: 255,
                nullable: false,
                comment: "YouTube ä�� URL",
                oldClrType: typeof(string),
                oldType: "nvarchar(255)",
                oldMaxLength: 255,
                oldComment: "YouTube 채널 URL");

            migrationBuilder.AlterColumn<DateTime>(
                name: "UpdatedAt",
                table: "Channel",
                type: "datetime2",
                nullable: true,
                comment: "���� �Ͻ�",
                oldClrType: typeof(DateTime),
                oldType: "datetime2",
                oldNullable: true,
                oldComment: "수정 일시");

            migrationBuilder.AlterColumn<string>(
                name: "SID",
                table: "Channel",
                type: "nvarchar(24)",
                maxLength: 24,
                nullable: false,
                comment: "ä�� ID",
                oldClrType: typeof(string),
                oldType: "nvarchar(24)",
                oldMaxLength: 24,
                oldComment: "채널 ID");

            migrationBuilder.AlterColumn<decimal>(
                name: "PlatformFeeRate",
                table: "Channel",
                type: "decimal(5,2)",
                precision: 5,
                scale: 2,
                nullable: false,
                comment: "������(%)",
                oldClrType: typeof(decimal),
                oldType: "decimal(5,2)",
                oldPrecision: 5,
                oldScale: 2,
                oldComment: "수수료(%)");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Channel",
                type: "nvarchar(200)",
                maxLength: 200,
                nullable: false,
                comment: "ä�� �̸�",
                oldClrType: typeof(string),
                oldType: "nvarchar(200)",
                oldMaxLength: 200,
                oldComment: "채널 이름");

            migrationBuilder.AlterColumn<int>(
                name: "MemberID",
                table: "Channel",
                type: "int",
                nullable: false,
                comment: "ȸ�� ID",
                oldClrType: typeof(int),
                oldType: "int",
                oldComment: "회원 ID");

            migrationBuilder.AlterColumn<bool>(
                name: "IsVerified",
                table: "Channel",
                type: "bit",
                nullable: false,
                comment: "���� ����",
                oldClrType: typeof(bool),
                oldType: "bit",
                oldComment: "인증 여부");

            migrationBuilder.AlterColumn<bool>(
                name: "IsActive",
                table: "Channel",
                type: "bit",
                nullable: false,
                comment: "Ȱ�� ����",
                oldClrType: typeof(bool),
                oldType: "bit",
                oldComment: "활성 여부");

            migrationBuilder.AlterColumn<string>(
                name: "Handle",
                table: "Channel",
                type: "nvarchar(30)",
                maxLength: 30,
                nullable: true,
                comment: "�ڵ�",
                oldClrType: typeof(string),
                oldType: "nvarchar(30)",
                oldMaxLength: 30,
                oldNullable: true,
                oldComment: "핸들");

            migrationBuilder.AlterColumn<DateTime>(
                name: "CreatedAt",
                table: "Channel",
                type: "datetime2",
                nullable: false,
                comment: "��� �Ͻ�",
                oldClrType: typeof(DateTime),
                oldType: "datetime2",
                oldComment: "등록 일시");

            migrationBuilder.CreateTable(
                name: "Crew",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    MinAmount = table.Column<int>(type: "int", nullable: true),
                    IsActive = table.Column<bool>(type: "bit", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Crew", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Crew_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Crew_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "크루");

            migrationBuilder.CreateTable(
                name: "DonationAlertConfig",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Amount = table.Column<int>(type: "int", nullable: false),
                    Sound = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    Message = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    PlayDelaySec = table.Column<double>(type: "float", nullable: false),
                    DisplayDurationSec = table.Column<double>(type: "float", nullable: false),
                    EnableThumbnail = table.Column<bool>(type: "bit", nullable: false),
                    ThumbnailUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    IsActive = table.Column<bool>(type: "bit", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationAlertConfig", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationAlertConfig_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationAlertConfig_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 알림 위젯 설정");

            migrationBuilder.CreateTable(
                name: "DonationGoalConfig",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Style = table.Column<int>(type: "int", nullable: false),
                    StartAmount = table.Column<int>(type: "int", nullable: false),
                    TargetAmount = table.Column<int>(type: "int", nullable: false),
                    StartAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    EndAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IsShowPercent = table.Column<bool>(type: "bit", nullable: false),
                    BarColor = table.Column<string>(type: "nvarchar(9)", maxLength: 9, nullable: false),
                    BarBackgroundColor = table.Column<string>(type: "nvarchar(9)", maxLength: 9, nullable: false),
                    BarHeightPx = table.Column<int>(type: "int", nullable: false),
                    TitleFontSizePx = table.Column<int>(type: "int", nullable: false),
                    TitleFontColor = table.Column<string>(type: "nvarchar(9)", maxLength: 9, nullable: false),
                    AmountFontSizePx = table.Column<int>(type: "int", nullable: false),
                    AmountFontColor = table.Column<string>(type: "nvarchar(9)", maxLength: 9, nullable: false),
                    IsActive = table.Column<bool>(type: "bit", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationGoalConfig", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationGoalConfig_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationGoalConfig_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 목표 위젯 설정");

            migrationBuilder.CreateTable(
                name: "DonationMeta",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    MinAmount = table.Column<int>(type: "int", nullable: false),
                    IsPaused = table.Column<bool>(type: "bit", nullable: false),
                    IsAccepting = table.Column<bool>(type: "bit", nullable: false),
                    IsAudioOnly = table.Column<bool>(type: "bit", nullable: false),
                    IsVideoOnly = table.Column<bool>(type: "bit", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationMeta", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationMeta_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationMeta_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 공통 설정");

            migrationBuilder.CreateTable(
                name: "DonationRankConfig",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(300)", maxLength: 300, nullable: false),
                    Theme = table.Column<int>(type: "int", nullable: false),
                    Period = table.Column<int>(type: "int", nullable: false),
                    StartAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    EndAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IsShowAmount = table.Column<bool>(type: "bit", nullable: false),
                    MaxRankCount = table.Column<int>(type: "int", nullable: false),
                    NameMode = table.Column<bool>(type: "bit", nullable: true),
                    IsActive = table.Column<bool>(type: "bit", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationRankConfig", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationRankConfig_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationRankConfig_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 순위 위젯 설정");

            migrationBuilder.CreateTable(
                name: "DonationRanking",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    SponsorMemberID = table.Column<int>(type: "int", nullable: false),
                    PeriodType = table.Column<int>(type: "int", nullable: false),
                    PeriodStart = table.Column<DateTime>(type: "datetime2", nullable: false),
                    PeriodEnd = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Rank = table.Column<int>(type: "int", nullable: false),
                    TotalAmount = table.Column<int>(type: "int", nullable: false),
                    DonationCount = table.Column<int>(type: "int", nullable: false),
                    SponsorName = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    IsActive = table.Column<bool>(type: "bit", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationRanking", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationRanking_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationRanking_Member_SponsorMemberID",
                        column: x => x.SponsorMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 순위");

            migrationBuilder.CreateTable(
                name: "MemberOAuthToken",
                columns: table => new
                {
                    ID = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    Provider = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    AccessTokenEnc = table.Column<string>(type: "nvarchar(2048)", maxLength: 2048, nullable: false),
                    RefreshTokenEnc = table.Column<string>(type: "nvarchar(2048)", maxLength: 2048, nullable: true),
                    ExpiresAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Scopes = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MemberOAuthToken", x => x.ID);
                    table.ForeignKey(
                        name: "FK_MemberOAuthToken_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "회원 OAuth 토큰");

            migrationBuilder.CreateTable(
                name: "Note",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    SenderMemberID = table.Column<int>(type: "int", nullable: false),
                    ReceiverMemberID = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Content = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
                    IsRead = table.Column<bool>(type: "bit", nullable: false),
                    IsDeletedBySender = table.Column<bool>(type: "bit", nullable: false),
                    IsDeletedByReceiver = table.Column<bool>(type: "bit", nullable: false),
                    IsSystem = table.Column<bool>(type: "bit", nullable: false),
                    RelatedType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RelatedID = table.Column<int>(type: "int", nullable: true),
                    ReadAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Note", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Note_Member_ReceiverMemberID",
                        column: x => x.ReceiverMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_Note_Member_SenderMemberID",
                        column: x => x.SenderMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "쪽지");

            migrationBuilder.CreateTable(
                name: "Notification",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Message = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
                    IsRead = table.Column<bool>(type: "bit", nullable: false),
                    ActionUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    RelatedType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RelatedID = table.Column<int>(type: "int", nullable: true),
                    ImageUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    ReadAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Notification", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Notification_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "알림");

            migrationBuilder.CreateTable(
                name: "Settlement",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    PeriodStart = table.Column<DateTime>(type: "datetime2", nullable: false),
                    PeriodEnd = table.Column<DateTime>(type: "datetime2", nullable: false),
                    GrossAmount = table.Column<int>(type: "int", nullable: false),
                    FeeAmount = table.Column<int>(type: "int", nullable: false),
                    NetAmount = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    RequestedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ApprovedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    PaidAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    AdminMemo = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Settlement", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Settlement_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_Settlement_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "정산");

            migrationBuilder.CreateTable(
                name: "CrewMember",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CrewID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    ChannelID = table.Column<int>(type: "int", nullable: true),
                    Nickname = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    Role = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    SortOrder = table.Column<int>(type: "int", nullable: false),
                    IsActive = table.Column<bool>(type: "bit", nullable: false),
                    JoinedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CrewMember", x => x.ID);
                    table.ForeignKey(
                        name: "FK_CrewMember_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_CrewMember_Crew_CrewID",
                        column: x => x.CrewID,
                        principalTable: "Crew",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_CrewMember_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "크루원");

            migrationBuilder.CreateTable(
                name: "CrewSession",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CrewID = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    StartedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    EndedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    TotalAmount = table.Column<int>(type: "int", nullable: false),
                    TotalDonationCount = table.Column<int>(type: "int", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CrewSession", x => x.ID);
                    table.ForeignKey(
                        name: "FK_CrewSession_Crew_CrewID",
                        column: x => x.CrewID,
                        principalTable: "Crew",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "크루 후원 방송 세션");

            migrationBuilder.CreateTable(
                name: "CrewDonationSummary",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CrewSessionID = table.Column<int>(type: "int", nullable: false),
                    CrewMemberID = table.Column<int>(type: "int", nullable: false),
                    TotalAmount = table.Column<int>(type: "int", nullable: false),
                    DonationCount = table.Column<int>(type: "int", nullable: false),
                    ContributionRate = table.Column<decimal>(type: "decimal(5,2)", precision: 5, scale: 2, nullable: false),
                    Rank = table.Column<int>(type: "int", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CrewDonationSummary", x => x.ID);
                    table.ForeignKey(
                        name: "FK_CrewDonationSummary_CrewMember_CrewMemberID",
                        column: x => x.CrewMemberID,
                        principalTable: "CrewMember",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_CrewDonationSummary_CrewSession_CrewSessionID",
                        column: x => x.CrewSessionID,
                        principalTable: "CrewSession",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "크루원 후원 집계");

            migrationBuilder.CreateTable(
                name: "CrewSessionConsent",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CrewSessionID = table.Column<int>(type: "int", nullable: false),
                    CrewMemberID = table.Column<int>(type: "int", nullable: false),
                    IsConsented = table.Column<bool>(type: "bit", nullable: false),
                    ConsentedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CrewSessionConsent", x => x.ID);
                    table.ForeignKey(
                        name: "FK_CrewSessionConsent_CrewMember_CrewMemberID",
                        column: x => x.CrewMemberID,
                        principalTable: "CrewMember",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_CrewSessionConsent_CrewSession_CrewSessionID",
                        column: x => x.CrewSessionID,
                        principalTable: "CrewSession",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "크루원 방송 동의");

            migrationBuilder.CreateTable(
                name: "Donation",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    SponsorMemberID = table.Column<int>(type: "int", nullable: false),
                    ReceiverMemberID = table.Column<int>(type: "int", nullable: false),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    CrewSessionID = table.Column<int>(type: "int", nullable: true),
                    CrewMemberID = table.Column<int>(type: "int", nullable: true),
                    Amount = table.Column<int>(type: "int", nullable: false),
                    FeeRate = table.Column<decimal>(type: "decimal(5,2)", precision: 5, scale: 2, nullable: false),
                    FeeAmount = table.Column<int>(type: "int", nullable: false),
                    NetAmount = table.Column<int>(type: "int", nullable: false),
                    Message = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    SendName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    IsTest = table.Column<bool>(type: "bit", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Donation", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Donation_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_Donation_CrewMember_CrewMemberID",
                        column: x => x.CrewMemberID,
                        principalTable: "CrewMember",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_Donation_CrewSession_CrewSessionID",
                        column: x => x.CrewSessionID,
                        principalTable: "CrewSession",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_Donation_Member_ReceiverMemberID",
                        column: x => x.ReceiverMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_Donation_Member_SponsorMemberID",
                        column: x => x.SponsorMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 내역");

            migrationBuilder.CreateTable(
                name: "DonationAlert",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    DonationID = table.Column<int>(type: "int", nullable: false),
                    SponsorMemberID = table.Column<int>(type: "int", nullable: false),
                    ReceiverMemberID = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    CorrelationID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    StartAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ArrivedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    TotalDelayMs = table.Column<double>(type: "float", nullable: true),
                    IpAddress = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UserAgent = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationAlert", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationAlert_Donation_DonationID",
                        column: x => x.DonationID,
                        principalTable: "Donation",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationAlert_Member_ReceiverMemberID",
                        column: x => x.ReceiverMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_DonationAlert_Member_SponsorMemberID",
                        column: x => x.SponsorMemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "후원 알림 추적");

            migrationBuilder.CreateTable(
                name: "DonationAlertAttempt",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    DonationID = table.Column<int>(type: "int", nullable: false),
                    DonationAlertID = table.Column<int>(type: "int", nullable: false),
                    IpAddress = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    UserAgent = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    SentAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DonationAlertAttempt", x => x.ID);
                    table.ForeignKey(
                        name: "FK_DonationAlertAttempt_DonationAlert_DonationAlertID",
                        column: x => x.DonationAlertID,
                        principalTable: "DonationAlert",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DonationAlertAttempt_Donation_DonationID",
                        column: x => x.DonationID,
                        principalTable: "Donation",
                        principalColumn: "ID");
                },
                comment: "후원 알림 재시도 기록");

            migrationBuilder.CreateIndex(
                name: "IX_Crew_ChannelID_IsActive",
                table: "Crew",
                columns: new[] { "ChannelID", "IsActive" });

            migrationBuilder.CreateIndex(
                name: "IX_Crew_MemberID",
                table: "Crew",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_CrewDonationSummary_CrewMemberID",
                table: "CrewDonationSummary",
                column: "CrewMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_CrewDonationSummary_CrewSessionID_CrewMemberID",
                table: "CrewDonationSummary",
                columns: new[] { "CrewSessionID", "CrewMemberID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_CrewDonationSummary_CrewSessionID_Rank",
                table: "CrewDonationSummary",
                columns: new[] { "CrewSessionID", "Rank" });

            migrationBuilder.CreateIndex(
                name: "IX_CrewMember_ChannelID",
                table: "CrewMember",
                column: "ChannelID");

            migrationBuilder.CreateIndex(
                name: "IX_CrewMember_CrewID_MemberID",
                table: "CrewMember",
                columns: new[] { "CrewID", "MemberID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_CrewMember_MemberID",
                table: "CrewMember",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_CrewSession_CrewID_StartedAt",
                table: "CrewSession",
                columns: new[] { "CrewID", "StartedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_CrewSession_CrewID_Status",
                table: "CrewSession",
                columns: new[] { "CrewID", "Status" });

            migrationBuilder.CreateIndex(
                name: "IX_CrewSessionConsent_CrewMemberID",
                table: "CrewSessionConsent",
                column: "CrewMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_CrewSessionConsent_CrewSessionID_CrewMemberID",
                table: "CrewSessionConsent",
                columns: new[] { "CrewSessionID", "CrewMemberID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Donation_ChannelID",
                table: "Donation",
                column: "ChannelID");

            migrationBuilder.CreateIndex(
                name: "IX_Donation_ChannelID_CreatedAt",
                table: "Donation",
                columns: new[] { "ChannelID", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_Donation_CrewMemberID",
                table: "Donation",
                column: "CrewMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_Donation_CrewSessionID",
                table: "Donation",
                column: "CrewSessionID");

            migrationBuilder.CreateIndex(
                name: "IX_Donation_ReceiverMemberID",
                table: "Donation",
                column: "ReceiverMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_Donation_SponsorMemberID",
                table: "Donation",
                column: "SponsorMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_Donation_SponsorMemberID_ReceiverMemberID",
                table: "Donation",
                columns: new[] { "SponsorMemberID", "ReceiverMemberID" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlert_CorrelationID",
                table: "DonationAlert",
                column: "CorrelationID",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlert_DonationID",
                table: "DonationAlert",
                column: "DonationID",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlert_ReceiverMemberID_Status_CreatedAt",
                table: "DonationAlert",
                columns: new[] { "ReceiverMemberID", "Status", "CreatedAt" },
                descending: new[] { false, false, true });

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlert_SponsorMemberID",
                table: "DonationAlert",
                column: "SponsorMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlert_Status",
                table: "DonationAlert",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlertAttempt_DonationAlertID",
                table: "DonationAlertAttempt",
                column: "DonationAlertID");

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlertAttempt_DonationID_DonationAlertID",
                table: "DonationAlertAttempt",
                columns: new[] { "DonationID", "DonationAlertID" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlertConfig_ChannelID_IsActive",
                table: "DonationAlertConfig",
                columns: new[] { "ChannelID", "IsActive" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlertConfig_ChannelID_MemberID_Amount",
                table: "DonationAlertConfig",
                columns: new[] { "ChannelID", "MemberID", "Amount" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationAlertConfig_MemberID",
                table: "DonationAlertConfig",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_DonationGoalConfig_ChannelID_IsActive",
                table: "DonationGoalConfig",
                columns: new[] { "ChannelID", "IsActive" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationGoalConfig_ChannelID_MemberID",
                table: "DonationGoalConfig",
                columns: new[] { "ChannelID", "MemberID" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationGoalConfig_MemberID",
                table: "DonationGoalConfig",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_DonationMeta_ChannelID_MemberID",
                table: "DonationMeta",
                columns: new[] { "ChannelID", "MemberID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DonationMeta_MemberID",
                table: "DonationMeta",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_DonationRankConfig_ChannelID_MemberID",
                table: "DonationRankConfig",
                columns: new[] { "ChannelID", "MemberID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DonationRankConfig_MemberID",
                table: "DonationRankConfig",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_DonationRanking_ChannelID_PeriodType_PeriodStart_Rank",
                table: "DonationRanking",
                columns: new[] { "ChannelID", "PeriodType", "PeriodStart", "Rank" });

            migrationBuilder.CreateIndex(
                name: "IX_DonationRanking_ChannelID_SponsorMemberID_PeriodType_PeriodStart",
                table: "DonationRanking",
                columns: new[] { "ChannelID", "SponsorMemberID", "PeriodType", "PeriodStart" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DonationRanking_SponsorMemberID",
                table: "DonationRanking",
                column: "SponsorMemberID");

            migrationBuilder.CreateIndex(
                name: "IX_MemberOAuthToken_MemberID_Provider",
                table: "MemberOAuthToken",
                columns: new[] { "MemberID", "Provider" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Note_ReceiverMemberID_IsDeletedByReceiver_IsRead_CreatedAt",
                table: "Note",
                columns: new[] { "ReceiverMemberID", "IsDeletedByReceiver", "IsRead", "CreatedAt" },
                descending: new[] { false, false, false, true });

            migrationBuilder.CreateIndex(
                name: "IX_Note_SenderMemberID_IsDeletedBySender_CreatedAt",
                table: "Note",
                columns: new[] { "SenderMemberID", "IsDeletedBySender", "CreatedAt" },
                descending: new[] { false, false, true });

            migrationBuilder.CreateIndex(
                name: "IX_Notification_MemberID_IsRead_CreatedAt",
                table: "Notification",
                columns: new[] { "MemberID", "IsRead", "CreatedAt" },
                descending: new[] { false, false, true });

            migrationBuilder.CreateIndex(
                name: "IX_Notification_MemberID_Type_CreatedAt",
                table: "Notification",
                columns: new[] { "MemberID", "Type", "CreatedAt" },
                descending: new[] { false, false, true });

            migrationBuilder.CreateIndex(
                name: "IX_Settlement_ChannelID_PeriodStart_PeriodEnd",
                table: "Settlement",
                columns: new[] { "ChannelID", "PeriodStart", "PeriodEnd" });

            migrationBuilder.CreateIndex(
                name: "IX_Settlement_MemberID",
                table: "Settlement",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_Settlement_Status",
                table: "Settlement",
                column: "Status");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "CrewDonationSummary");

            migrationBuilder.DropTable(
                name: "CrewSessionConsent");

            migrationBuilder.DropTable(
                name: "DonationAlertAttempt");

            migrationBuilder.DropTable(
                name: "DonationAlertConfig");

            migrationBuilder.DropTable(
                name: "DonationGoalConfig");

            migrationBuilder.DropTable(
                name: "DonationMeta");

            migrationBuilder.DropTable(
                name: "DonationRankConfig");

            migrationBuilder.DropTable(
                name: "DonationRanking");

            migrationBuilder.DropTable(
                name: "MemberOAuthToken");

            migrationBuilder.DropTable(
                name: "Note");

            migrationBuilder.DropTable(
                name: "Notification");

            migrationBuilder.DropTable(
                name: "Settlement");

            migrationBuilder.DropTable(
                name: "DonationAlert");

            migrationBuilder.DropTable(
                name: "Donation");

            migrationBuilder.DropTable(
                name: "CrewMember");

            migrationBuilder.DropTable(
                name: "CrewSession");

            migrationBuilder.DropTable(
                name: "Crew");

            migrationBuilder.AlterTable(
                name: "Channel",
                comment: "채널 정보",
                oldComment: "ä�� ����");

            migrationBuilder.AlterColumn<string>(
                name: "YouTubeUrl",
                table: "Channel",
                type: "nvarchar(255)",
                maxLength: 255,
                nullable: false,
                comment: "YouTube 채널 URL",
                oldClrType: typeof(string),
                oldType: "nvarchar(255)",
                oldMaxLength: 255,
                oldComment: "YouTube ä�� URL");

            migrationBuilder.AlterColumn<DateTime>(
                name: "UpdatedAt",
                table: "Channel",
                type: "datetime2",
                nullable: true,
                comment: "수정 일시",
                oldClrType: typeof(DateTime),
                oldType: "datetime2",
                oldNullable: true,
                oldComment: "���� �Ͻ�");

            migrationBuilder.AlterColumn<string>(
                name: "SID",
                table: "Channel",
                type: "nvarchar(24)",
                maxLength: 24,
                nullable: false,
                comment: "채널 ID",
                oldClrType: typeof(string),
                oldType: "nvarchar(24)",
                oldMaxLength: 24,
                oldComment: "ä�� ID");

            migrationBuilder.AlterColumn<decimal>(
                name: "PlatformFeeRate",
                table: "Channel",
                type: "decimal(5,2)",
                precision: 5,
                scale: 2,
                nullable: false,
                comment: "수수료(%)",
                oldClrType: typeof(decimal),
                oldType: "decimal(5,2)",
                oldPrecision: 5,
                oldScale: 2,
                oldComment: "������(%)");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Channel",
                type: "nvarchar(200)",
                maxLength: 200,
                nullable: false,
                comment: "채널 이름",
                oldClrType: typeof(string),
                oldType: "nvarchar(200)",
                oldMaxLength: 200,
                oldComment: "ä�� �̸�");

            migrationBuilder.AlterColumn<int>(
                name: "MemberID",
                table: "Channel",
                type: "int",
                nullable: false,
                comment: "회원 ID",
                oldClrType: typeof(int),
                oldType: "int",
                oldComment: "ȸ�� ID");

            migrationBuilder.AlterColumn<bool>(
                name: "IsVerified",
                table: "Channel",
                type: "bit",
                nullable: false,
                comment: "인증 여부",
                oldClrType: typeof(bool),
                oldType: "bit",
                oldComment: "���� ����");

            migrationBuilder.AlterColumn<bool>(
                name: "IsActive",
                table: "Channel",
                type: "bit",
                nullable: false,
                comment: "활성 여부",
                oldClrType: typeof(bool),
                oldType: "bit",
                oldComment: "Ȱ�� ����");

            migrationBuilder.AlterColumn<string>(
                name: "Handle",
                table: "Channel",
                type: "nvarchar(30)",
                maxLength: 30,
                nullable: true,
                comment: "핸들",
                oldClrType: typeof(string),
                oldType: "nvarchar(30)",
                oldMaxLength: 30,
                oldNullable: true,
                oldComment: "�ڵ�");

            migrationBuilder.AlterColumn<DateTime>(
                name: "CreatedAt",
                table: "Channel",
                type: "datetime2",
                nullable: false,
                comment: "등록 일시",
                oldClrType: typeof(DateTime),
                oldType: "datetime2",
                oldComment: "��� �Ͻ�");
        }
    }
}
