20241010142722_FixedItemValueReferenceStyle.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Jellyfin.Server.Implementations.Migrations
  5. {
  6. /// <inheritdoc />
  7. public partial class FixedItemValueReferenceStyle : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.DropForeignKey(
  13. name: "FK_ItemValues_BaseItems_ItemId",
  14. table: "ItemValues");
  15. migrationBuilder.DropPrimaryKey(
  16. name: "PK_ItemValues",
  17. table: "ItemValues");
  18. migrationBuilder.DropIndex(
  19. name: "IX_ItemValues_ItemId_Type_CleanValue",
  20. table: "ItemValues");
  21. migrationBuilder.RenameColumn(
  22. name: "ItemId",
  23. table: "ItemValues",
  24. newName: "ItemValueId");
  25. migrationBuilder.AddPrimaryKey(
  26. name: "PK_ItemValues",
  27. table: "ItemValues",
  28. column: "ItemValueId");
  29. migrationBuilder.CreateTable(
  30. name: "ItemValuesMap",
  31. columns: table => new
  32. {
  33. ItemId = table.Column<Guid>(type: "TEXT", nullable: false),
  34. ItemValueId = table.Column<Guid>(type: "TEXT", nullable: false)
  35. },
  36. constraints: table =>
  37. {
  38. table.PrimaryKey("PK_ItemValuesMap", x => new { x.ItemValueId, x.ItemId });
  39. table.ForeignKey(
  40. name: "FK_ItemValuesMap_BaseItems_ItemId",
  41. column: x => x.ItemId,
  42. principalTable: "BaseItems",
  43. principalColumn: "Id",
  44. onDelete: ReferentialAction.Cascade);
  45. table.ForeignKey(
  46. name: "FK_ItemValuesMap_ItemValues_ItemValueId",
  47. column: x => x.ItemValueId,
  48. principalTable: "ItemValues",
  49. principalColumn: "ItemValueId",
  50. onDelete: ReferentialAction.Cascade);
  51. });
  52. migrationBuilder.CreateIndex(
  53. name: "IX_ItemValues_Type_CleanValue",
  54. table: "ItemValues",
  55. columns: new[] { "Type", "CleanValue" });
  56. migrationBuilder.CreateIndex(
  57. name: "IX_ItemValuesMap_ItemId",
  58. table: "ItemValuesMap",
  59. column: "ItemId");
  60. migrationBuilder.AddForeignKey(
  61. name: "FK_AncestorIds_BaseItems_ItemId",
  62. table: "AncestorIds",
  63. column: "ItemId",
  64. principalTable: "BaseItems",
  65. principalColumn: "Id",
  66. onDelete: ReferentialAction.Cascade);
  67. migrationBuilder.AddForeignKey(
  68. name: "FK_AncestorIds_BaseItems_ParentItemId",
  69. table: "AncestorIds",
  70. column: "ParentItemId",
  71. principalTable: "BaseItems",
  72. principalColumn: "Id",
  73. onDelete: ReferentialAction.Cascade);
  74. }
  75. /// <inheritdoc />
  76. protected override void Down(MigrationBuilder migrationBuilder)
  77. {
  78. migrationBuilder.DropForeignKey(
  79. name: "FK_AncestorIds_BaseItems_ItemId",
  80. table: "AncestorIds");
  81. migrationBuilder.DropForeignKey(
  82. name: "FK_AncestorIds_BaseItems_ParentItemId",
  83. table: "AncestorIds");
  84. migrationBuilder.DropTable(
  85. name: "ItemValuesMap");
  86. migrationBuilder.DropPrimaryKey(
  87. name: "PK_ItemValues",
  88. table: "ItemValues");
  89. migrationBuilder.DropIndex(
  90. name: "IX_ItemValues_Type_CleanValue",
  91. table: "ItemValues");
  92. migrationBuilder.RenameColumn(
  93. name: "ItemValueId",
  94. table: "ItemValues",
  95. newName: "ItemId");
  96. migrationBuilder.AddPrimaryKey(
  97. name: "PK_ItemValues",
  98. table: "ItemValues",
  99. columns: new[] { "ItemId", "Type", "Value" });
  100. migrationBuilder.CreateIndex(
  101. name: "IX_ItemValues_ItemId_Type_CleanValue",
  102. table: "ItemValues",
  103. columns: new[] { "ItemId", "Type", "CleanValue" });
  104. migrationBuilder.AddForeignKey(
  105. name: "FK_ItemValues_BaseItems_ItemId",
  106. table: "ItemValues",
  107. column: "ItemId",
  108. principalTable: "BaseItems",
  109. principalColumn: "Id",
  110. onDelete: ReferentialAction.Cascade);
  111. }
  112. }
  113. }