20260313180453_AddRssNewsTables.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb;
  5. /// <inheritdoc />
  6. public partial class AddRssNewsTables : Migration
  7. {
  8. /// <inheritdoc />
  9. protected override void Up(MigrationBuilder migrationBuilder)
  10. {
  11. migrationBuilder.CreateTable(
  12. name: "RssFeedSource",
  13. columns: table => new
  14. {
  15. ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
  16. .Annotation("SqlServer:Identity", "1, 1"),
  17. Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false, comment: "소스 이름"),
  18. Url = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false, comment: "RSS 피드 URL"),
  19. Description = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "소스 설명"),
  20. IntervalMinutes = table.Column<int>(type: "int", nullable: false, comment: "수집 주기 (분)"),
  21. IsActive = table.Column<bool>(type: "bit", nullable: false, comment: "활성화 여부"),
  22. LastFetchedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "마지막 수집 일시"),
  23. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "수정 일시"),
  24. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "등록 일시")
  25. },
  26. constraints: table =>
  27. {
  28. table.PrimaryKey("PK_RssFeedSource", x => x.ID);
  29. },
  30. comment: "RSS 피드 소스");
  31. migrationBuilder.CreateTable(
  32. name: "RssNewsArticle",
  33. columns: table => new
  34. {
  35. ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
  36. .Annotation("SqlServer:Identity", "1, 1"),
  37. RssFeedSourceID = table.Column<int>(type: "int", nullable: false, comment: "RSS 피드 소스 FK"),
  38. Title = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false, comment: "기사 제목"),
  39. Link = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true, comment: "원본 링크"),
  40. Guid = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true, comment: "RSS GUID (중복 방지)"),
  41. Author = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true, comment: "작성자"),
  42. Description = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "요약"),
  43. Content = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "본문 (content:encoded)"),
  44. ImageUrl = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true, comment: "썸네일 이미지 URL"),
  45. SourceName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true, comment: "출처명"),
  46. Categories = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "카테고리 (JSON 배열)"),
  47. CommentCount = table.Column<int>(type: "int", nullable: false, comment: "댓글 수"),
  48. PublishedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "발행 일시"),
  49. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "수집 일시")
  50. },
  51. constraints: table =>
  52. {
  53. table.PrimaryKey("PK_RssNewsArticle", x => x.ID);
  54. table.ForeignKey(
  55. name: "FK_RssNewsArticle_RssFeedSource_RssFeedSourceID",
  56. column: x => x.RssFeedSourceID,
  57. principalTable: "RssFeedSource",
  58. principalColumn: "ID",
  59. onDelete: ReferentialAction.Cascade);
  60. },
  61. comment: "RSS 뉴스 기사");
  62. migrationBuilder.CreateIndex(
  63. name: "IX_RssFeedSource_IsActive",
  64. table: "RssFeedSource",
  65. column: "IsActive");
  66. migrationBuilder.CreateIndex(
  67. name: "IX_RssFeedSource_Url",
  68. table: "RssFeedSource",
  69. column: "Url",
  70. unique: true);
  71. migrationBuilder.CreateIndex(
  72. name: "IX_RssNewsArticle_CreatedAt",
  73. table: "RssNewsArticle",
  74. column: "CreatedAt");
  75. migrationBuilder.CreateIndex(
  76. name: "IX_RssNewsArticle_Guid_RssFeedSourceID",
  77. table: "RssNewsArticle",
  78. columns: new[] { "Guid", "RssFeedSourceID" },
  79. unique: true,
  80. filter: "[Guid] IS NOT NULL");
  81. migrationBuilder.CreateIndex(
  82. name: "IX_RssNewsArticle_PublishedAt",
  83. table: "RssNewsArticle",
  84. column: "PublishedAt");
  85. migrationBuilder.CreateIndex(
  86. name: "IX_RssNewsArticle_RssFeedSourceID",
  87. table: "RssNewsArticle",
  88. column: "RssFeedSourceID");
  89. }
  90. /// <inheritdoc />
  91. protected override void Down(MigrationBuilder migrationBuilder)
  92. {
  93. migrationBuilder.DropTable(
  94. name: "RssNewsArticle");
  95. migrationBuilder.DropTable(
  96. name: "RssFeedSource");
  97. }
  98. }