using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Infrastructure.Migrations.AppDb
{
    /// <inheritdoc />
    public partial class AddWidgetTokenToChannel : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "WidgetToken",
                table: "Channel",
                type: "nvarchar(32)",
                maxLength: 32,
                nullable: false,
                defaultValue: "",
                comment: "위젯 토큰");

            // 기존 채널에 고유 토큰 생성
            migrationBuilder.Sql("UPDATE [Channel] SET [WidgetToken] = LOWER(REPLACE(CAST(NEWID() AS NVARCHAR(36)), '-', ''))");

            migrationBuilder.CreateIndex(
                name: "IX_Channel_WidgetToken",
                table: "Channel",
                column: "WidgetToken",
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_Channel_WidgetToken",
                table: "Channel");

            migrationBuilder.DropColumn(
                name: "WidgetToken",
                table: "Channel");
        }
    }
}
