20260322084019_AddPostViewLog.cs 2.0 KB

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