20260322084019_AddPostViewLog.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddPostViewLog : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.CreateTable(
  13. name: "PostViewLog",
  14. columns: table => new
  15. {
  16. ID = table.Column<int>(type: "int", nullable: false)
  17. .Annotation("SqlServer:Identity", "1, 1"),
  18. PostID = table.Column<int>(type: "int", nullable: false),
  19. MemberID = table.Column<int>(type: "int", nullable: true),
  20. IpAddress = table.Column<string>(type: "nvarchar(max)", nullable: true),
  21. UserAgent = table.Column<string>(type: "nvarchar(max)", nullable: true),
  22. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  23. },
  24. constraints: table =>
  25. {
  26. table.PrimaryKey("PK_PostViewLog", x => x.ID);
  27. table.ForeignKey(
  28. name: "FK_PostViewLog_Member_MemberID",
  29. column: x => x.MemberID,
  30. principalTable: "Member",
  31. principalColumn: "ID");
  32. table.ForeignKey(
  33. name: "FK_PostViewLog_Post_PostID",
  34. column: x => x.PostID,
  35. principalTable: "Post",
  36. principalColumn: "ID",
  37. onDelete: ReferentialAction.Cascade);
  38. });
  39. migrationBuilder.CreateIndex(
  40. name: "IX_PostViewLog_MemberID",
  41. table: "PostViewLog",
  42. column: "MemberID");
  43. migrationBuilder.CreateIndex(
  44. name: "IX_PostViewLog_PostID",
  45. table: "PostViewLog",
  46. column: "PostID");
  47. }
  48. /// <inheritdoc />
  49. protected override void Down(MigrationBuilder migrationBuilder)
  50. {
  51. migrationBuilder.DropTable(
  52. name: "PostViewLog");
  53. }
  54. }
  55. }