20260327174018_AddWidgetTokenToChannel.cs 1.3 KB

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