Add issues table

This commit is contained in:
Zoe Roux 2024-02-17 15:50:05 +01:00
parent 7f20a3f36a
commit 2b59a35bf3
5 changed files with 1479 additions and 0 deletions

View File

@ -0,0 +1,52 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
namespace Kyoo.Abstractions.Models;
/// <summary>
/// An issue that occured on kyoo.
/// </summary>
public class Issue : IAddedDate
{
/// <summary>
/// The type of issue (for example, "Scanner" if this issue was created due to scanning error).
/// </summary>
public string Domain { get; set; }
/// <summary>
/// Why this issue was caused? An unique cause that can be used to identify this issue.
/// For the scanner, a cause should be a video path.
/// </summary>
public string Cause { get; set; }
/// <summary>
/// A human readable string explaining why this issue occured.
/// </summary>
public string Reason { get; set; }
/// <summary>
/// Some extra data that could store domain-specific info.
/// </summary>
public Dictionary<string, object> Extra { get; set; }
/// <inheritdoc/>
public DateTime AddedDate { get; set; }
}

View File

@ -104,6 +104,8 @@ namespace Kyoo.Postgresql
public DbSet<EpisodeWatchStatus> EpisodeWatchStatus { get; set; }
public DbSet<Issue> Issues { get; set; }
/// <summary>
/// Add a many to many link between two resources.
/// </summary>
@ -314,6 +316,7 @@ namespace Kyoo.Postgresql
_HasAddedDate<Season>(modelBuilder);
_HasAddedDate<Episode>(modelBuilder);
_HasAddedDate<User>(modelBuilder);
_HasAddedDate<Issue>(modelBuilder);
modelBuilder
.Entity<User>()
@ -405,6 +408,28 @@ namespace Kyoo.Postgresql
modelBuilder.Entity<User>().HasIndex(x => x.Slug).IsUnique();
modelBuilder.Entity<Movie>().Ignore(x => x.Links);
modelBuilder.Entity<Issue>()
.HasKey(x => new { x.Domain, x.Cause });
// TODO: Waiting for https://github.com/dotnet/efcore/issues/29825
// modelBuilder.Entity<T>()
// .OwnsOne(x => x.ExternalId, x =>
// {
// x.ToJson();
// });
modelBuilder.Entity<Issue>()
.Property(x => x.Extra)
.HasConversion(
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
v =>
JsonSerializer.Deserialize<Dictionary<string, object>>(
v,
(JsonSerializerOptions?)null
)!
)
.HasColumnType("json");
}
/// <summary>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
public partial class AddIssues : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_show_watch_status_episodes_next_episode_id",
table: "show_watch_status");
migrationBuilder.CreateTable(
name: "issues",
columns: table => new
{
domain = table.Column<string>(type: "text", nullable: false),
cause = table.Column<string>(type: "text", nullable: false),
reason = table.Column<string>(type: "text", nullable: false),
extra = table.Column<string>(type: "json", nullable: false),
added_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'")
},
constraints: table =>
{
table.PrimaryKey("pk_issues", x => new { x.domain, x.cause });
});
migrationBuilder.AddForeignKey(
name: "fk_show_watch_status_episodes_next_episode_id",
table: "show_watch_status",
column: "next_episode_id",
principalTable: "episodes",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_show_watch_status_episodes_next_episode_id",
table: "show_watch_status");
migrationBuilder.DropTable(
name: "issues");
migrationBuilder.AddForeignKey(
name: "fk_show_watch_status_episodes_next_episode_id",
table: "show_watch_status",
column: "next_episode_id",
principalTable: "episodes",
principalColumn: "id");
}
}
}

View File

@ -193,6 +193,38 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_watch_status", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.Issue", b =>
{
b.Property<string>("Domain")
.HasColumnType("text")
.HasColumnName("domain");
b.Property<string>("Cause")
.HasColumnType("text")
.HasColumnName("cause");
b.Property<DateTime>("AddedDate")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("added_date")
.HasDefaultValueSql("now() at time zone 'utc'");
b.Property<string>("Extra")
.IsRequired()
.HasColumnType("json")
.HasColumnName("extra");
b.Property<string>("Reason")
.IsRequired()
.HasColumnType("text")
.HasColumnName("reason");
b.HasKey("Domain", "Cause")
.HasName("pk_issues");
b.ToTable("issues", (string)null);
});
modelBuilder.Entity("Kyoo.Abstractions.Models.Movie", b =>
{
b.Property<Guid>("Id")
@ -1180,6 +1212,7 @@ namespace Kyoo.Postgresql.Migrations
b.HasOne("Kyoo.Abstractions.Models.Episode", "NextEpisode")
.WithMany()
.HasForeignKey("NextEpisodeId")
.OnDelete(DeleteBehavior.SetNull)
.HasConstraintName("fk_show_watch_status_episodes_next_episode_id");
b.HasOne("Kyoo.Abstractions.Models.Show", "Show")