Refactored ItemValue structure

This commit is contained in:
JPVenson
2024-10-10 14:32:49 +00:00
parent 3e7ce5e1df
commit ee0dad6f43
14 changed files with 1970 additions and 106 deletions

View File

@@ -0,0 +1,133 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Jellyfin.Server.Implementations.Migrations
{
/// <inheritdoc />
public partial class FixedItemValueReferenceStyle : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ItemValues_BaseItems_ItemId",
table: "ItemValues");
migrationBuilder.DropPrimaryKey(
name: "PK_ItemValues",
table: "ItemValues");
migrationBuilder.DropIndex(
name: "IX_ItemValues_ItemId_Type_CleanValue",
table: "ItemValues");
migrationBuilder.RenameColumn(
name: "ItemId",
table: "ItemValues",
newName: "ItemValueId");
migrationBuilder.AddPrimaryKey(
name: "PK_ItemValues",
table: "ItemValues",
column: "ItemValueId");
migrationBuilder.CreateTable(
name: "ItemValuesMap",
columns: table => new
{
ItemId = table.Column<Guid>(type: "TEXT", nullable: false),
ItemValueId = table.Column<Guid>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ItemValuesMap", x => new { x.ItemValueId, x.ItemId });
table.ForeignKey(
name: "FK_ItemValuesMap_BaseItems_ItemId",
column: x => x.ItemId,
principalTable: "BaseItems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ItemValuesMap_ItemValues_ItemValueId",
column: x => x.ItemValueId,
principalTable: "ItemValues",
principalColumn: "ItemValueId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ItemValues_Type_CleanValue",
table: "ItemValues",
columns: new[] { "Type", "CleanValue" });
migrationBuilder.CreateIndex(
name: "IX_ItemValuesMap_ItemId",
table: "ItemValuesMap",
column: "ItemId");
migrationBuilder.AddForeignKey(
name: "FK_AncestorIds_BaseItems_ItemId",
table: "AncestorIds",
column: "ItemId",
principalTable: "BaseItems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_AncestorIds_BaseItems_ParentItemId",
table: "AncestorIds",
column: "ParentItemId",
principalTable: "BaseItems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_AncestorIds_BaseItems_ItemId",
table: "AncestorIds");
migrationBuilder.DropForeignKey(
name: "FK_AncestorIds_BaseItems_ParentItemId",
table: "AncestorIds");
migrationBuilder.DropTable(
name: "ItemValuesMap");
migrationBuilder.DropPrimaryKey(
name: "PK_ItemValues",
table: "ItemValues");
migrationBuilder.DropIndex(
name: "IX_ItemValues_Type_CleanValue",
table: "ItemValues");
migrationBuilder.RenameColumn(
name: "ItemValueId",
table: "ItemValues",
newName: "ItemId");
migrationBuilder.AddPrimaryKey(
name: "PK_ItemValues",
table: "ItemValues",
columns: new[] { "ItemId", "Type", "Value" });
migrationBuilder.CreateIndex(
name: "IX_ItemValues_ItemId_Type_CleanValue",
table: "ItemValues",
columns: new[] { "ItemId", "Type", "CleanValue" });
migrationBuilder.AddForeignKey(
name: "FK_ItemValues_BaseItems_ItemId",
table: "ItemValues",
column: "ItemId",
principalTable: "BaseItems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -683,26 +683,43 @@ namespace Jellyfin.Server.Implementations.Migrations
modelBuilder.Entity("Jellyfin.Data.Entities.ItemValue", b =>
{
b.Property<Guid>("ItemId")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<string>("Value")
b.Property<Guid>("ItemValueId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CleanValue")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ItemId", "Type", "Value");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasIndex("ItemId", "Type", "CleanValue");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ItemValueId");
b.HasIndex("Type", "CleanValue");
b.ToTable("ItemValues");
});
modelBuilder.Entity("Jellyfin.Data.Entities.ItemValueMap", b =>
{
b.Property<Guid>("ItemValueId")
.HasColumnType("TEXT");
b.Property<Guid>("ItemId")
.HasColumnType("TEXT");
b.HasKey("ItemValueId", "ItemId");
b.HasIndex("ItemId");
b.ToTable("ItemValuesMap");
});
modelBuilder.Entity("Jellyfin.Data.Entities.MediaSegment", b =>
{
b.Property<Guid>("Id")
@@ -1307,6 +1324,22 @@ namespace Jellyfin.Server.Implementations.Migrations
b.HasOne("Jellyfin.Data.Entities.BaseItemEntity", null)
.WithMany("AncestorIds")
.HasForeignKey("BaseItemEntityId");
b.HasOne("Jellyfin.Data.Entities.BaseItemEntity", "Item")
.WithMany()
.HasForeignKey("ItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Jellyfin.Data.Entities.BaseItemEntity", "ParentItem")
.WithMany()
.HasForeignKey("ParentItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Item");
b.Navigation("ParentItem");
});
modelBuilder.Entity("Jellyfin.Data.Entities.AttachmentStreamInfo", b =>
@@ -1410,7 +1443,7 @@ namespace Jellyfin.Server.Implementations.Migrations
.IsRequired();
});
modelBuilder.Entity("Jellyfin.Data.Entities.ItemValue", b =>
modelBuilder.Entity("Jellyfin.Data.Entities.ItemValueMap", b =>
{
b.HasOne("Jellyfin.Data.Entities.BaseItemEntity", "Item")
.WithMany("ItemValues")
@@ -1418,7 +1451,15 @@ namespace Jellyfin.Server.Implementations.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Jellyfin.Data.Entities.ItemValue", "ItemValue")
.WithMany("BaseItemsMap")
.HasForeignKey("ItemValueId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Item");
b.Navigation("ItemValue");
});
modelBuilder.Entity("Jellyfin.Data.Entities.MediaStreamInfo", b =>
@@ -1513,6 +1554,11 @@ namespace Jellyfin.Server.Implementations.Migrations
b.Navigation("HomeSections");
});
modelBuilder.Entity("Jellyfin.Data.Entities.ItemValue", b =>
{
b.Navigation("BaseItemsMap");
});
modelBuilder.Entity("Jellyfin.Data.Entities.User", b =>
{
b.Navigation("AccessSchedules");