20260327174018_AddWidgetTokenToChannel.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Microsoft.EntityFrameworkCore.Migrations;
  2. #nullable disable
  3. namespace Infrastructure.Migrations.AppDb;
  4. /// <inheritdoc />
  5. public partial class AddWidgetTokenToChannel : Migration
  6. {
  7. /// <inheritdoc />
  8. protected override void Up(MigrationBuilder migrationBuilder)
  9. {
  10. migrationBuilder.AddColumn<string>(
  11. name: "WidgetToken",
  12. table: "Channel",
  13. type: "nvarchar(32)",
  14. maxLength: 32,
  15. nullable: false,
  16. defaultValue: "",
  17. comment: "위젯 토큰");
  18. // 기존 채널에 고유 토큰 생성
  19. migrationBuilder.Sql("UPDATE [Channel] SET [WidgetToken] = LOWER(REPLACE(CAST(NEWID() AS NVARCHAR(36)), '-', ''))");
  20. migrationBuilder.CreateIndex(
  21. name: "IX_Channel_WidgetToken",
  22. table: "Channel",
  23. column: "WidgetToken",
  24. unique: true);
  25. }
  26. /// <inheritdoc />
  27. protected override void Down(MigrationBuilder migrationBuilder)
  28. {
  29. migrationBuilder.DropIndex(
  30. name: "IX_Channel_WidgetToken",
  31. table: "Channel");
  32. migrationBuilder.DropColumn(
  33. name: "WidgetToken",
  34. table: "Channel");
  35. }
  36. }