ShowLink: Fixing them and testing it

This commit is contained in:
Zoe Roux 2021-08-01 19:21:23 +02:00
parent 7540adb822
commit 6566b717f6
17 changed files with 1094 additions and 1192 deletions

View File

@ -1,163 +0,0 @@
using System;
using System.Linq.Expressions;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
{
/// <summary>
/// A class representing a link between two resources.
/// </summary>
/// <remarks>
/// Links should only be used on the data layer and not on other application code.
/// </remarks>
public class Link
{
/// <summary>
/// The ID of the first item of the link.
/// The first item of the link should be the one to own the link.
/// </summary>
public int FirstID { get; set; }
/// <summary>
/// The ID of the second item of this link
/// The second item of the link should be the owned resource.
/// </summary>
public int SecondID { get; set; }
/// <summary>
/// Create a new typeless <see cref="Link"/>.
/// </summary>
public Link() {}
/// <summary>
/// Create a new typeless <see cref="Link"/> with two IDs.
/// </summary>
/// <param name="firstID">The ID of the first resource</param>
/// <param name="secondID">The ID of the second resource</param>
public Link(int firstID, int secondID)
{
FirstID = firstID;
SecondID = secondID;
}
/// <summary>
/// Create a new typeless <see cref="Link"/> between two resources.
/// </summary>
/// <param name="first">The first resource</param>
/// <param name="second">The second resource</param>
public Link(IResource first, IResource second)
{
FirstID = first.ID;
SecondID = second.ID;
}
/// <summary>
/// Create a new typed link between two resources.
/// This method can be used instead of the constructor to make use of generic parameters deduction.
/// </summary>
/// <param name="first">The first resource</param>
/// <param name="second">The second resource</param>
/// <typeparam name="T">The type of the first resource</typeparam>
/// <typeparam name="T2">The type of the second resource</typeparam>
/// <returns>A newly created typed link with both resources</returns>
public static Link<T, T2> Create<T, T2>(T first, T2 second)
where T : class, IResource
where T2 : class, IResource
{
return new(first, second);
}
/// <summary>
/// Create a new typed link between two resources without storing references to resources.
/// This is the same as <see cref="Create{T,T2}"/> but this method does not set <see cref="Link{T1,T2}.First"/>
/// and <see cref="Link{T1,T2}.Second"/> fields. Only IDs are stored and not references.
/// </summary>
/// <param name="first">The first resource</param>
/// <param name="second">The second resource</param>
/// <typeparam name="T">The type of the first resource</typeparam>
/// <typeparam name="T2">The type of the second resource</typeparam>
/// <returns>A newly created typed link with both resources</returns>
public static Link<T, T2> UCreate<T, T2>(T first, T2 second)
where T : class, IResource
where T2 : class, IResource
{
return new(first, second, true);
}
/// <summary>
/// The expression to retrieve the unique ID of a Link. This is an aggregate of the two resources IDs.
/// </summary>
public static Expression<Func<Link, object>> PrimaryKey
{
get
{
return x => new {First = x.FirstID, Second = x.SecondID};
}
}
}
/// <summary>
/// A strongly typed link between two resources.
/// </summary>
/// <typeparam name="T1">The type of the first resource</typeparam>
/// <typeparam name="T2">The type of the second resource</typeparam>
public class Link<T1, T2> : Link
where T1 : class, IResource
where T2 : class, IResource
{
/// <summary>
/// A reference of the first resource.
/// </summary>
[SerializeIgnore] public T1 First { get; set; }
/// <summary>
/// A reference to the second resource.
/// </summary>
[SerializeIgnore] public T2 Second { get; set; }
/// <summary>
/// Create a new, empty, typed <see cref="Link{T1,T2}"/>.
/// </summary>
public Link() {}
/// <summary>
/// Create a new typed link with two resources.
/// </summary>
/// <param name="first">The first resource</param>
/// <param name="second">The second resource</param>
/// <param name="privateItems">
/// True if no reference to resources should be kept, false otherwise.
/// The default is false (references are kept).
/// </param>
public Link(T1 first, T2 second, bool privateItems = false)
: base(first, second)
{
if (privateItems)
return;
First = first;
Second = second;
}
/// <summary>
/// Create a new typed link with IDs only.
/// </summary>
/// <param name="firstID">The ID of the first resource</param>
/// <param name="secondID">The ID of the second resource</param>
public Link(int firstID, int secondID)
: base(firstID, secondID)
{ }
/// <summary>
/// The expression to retrieve the unique ID of a typed Link. This is an aggregate of the two resources IDs.
/// </summary>
public new static Expression<Func<Link<T1, T2>, object>> PrimaryKey
{
get
{
return x => new {First = x.FirstID, Second = x.SecondID};
}
}
}
}

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading; using System.Threading;
@ -96,17 +97,23 @@ namespace Kyoo
} }
/// <summary> /// <summary>
/// Get a generic link between two resource types. /// Add a many to many link between two resources.
/// </summary> /// </summary>
/// <remarks>Types are order dependant. You can't inverse the order. Please always put the owner first.</remarks> /// <remarks>Types are order dependant. You can't inverse the order. Please always put the owner first.</remarks>
/// <param name="first">The ID of the first resource.</param>
/// <param name="second">The ID of the second resource.</param>
/// <typeparam name="T1">The first resource type of the relation. It is the owner of the second</typeparam> /// <typeparam name="T1">The first resource type of the relation. It is the owner of the second</typeparam>
/// <typeparam name="T2">The second resource type of the relation. It is the contained resource.</typeparam> /// <typeparam name="T2">The second resource type of the relation. It is the contained resource.</typeparam>
/// <returns>All links between the two types.</returns> public async Task AddLinks<T1, T2>(int first, int second)
public DbSet<Link<T1, T2>> Links<T1, T2>()
where T1 : class, IResource where T1 : class, IResource
where T2 : class, IResource where T2 : class, IResource
{ {
return Set<Link<T1, T2>>(); await Set<Dictionary<string, object>>(LinkName<T1, T2>())
.AddAsync(new Dictionary<string, object>
{
[LinkNameFk<T1>()] = first,
[LinkNameFk<T2>()] = second
});
} }
@ -141,6 +148,14 @@ namespace Kyoo
where T : IResource where T : IResource
where T2 : IResource; where T2 : IResource;
/// <summary>
/// Get the name of a link's foreign key.
/// </summary>
/// <typeparam name="T">The type that will be accessible via the navigation</typeparam>
/// <returns>The name of the foreign key for the given resource.</returns>
protected abstract string LinkNameFk<T>()
where T : IResource;
/// <summary> /// <summary>
/// Set basic configurations (like preventing query tracking) /// Set basic configurations (like preventing query tracking)
/// </summary> /// </summary>
@ -168,6 +183,39 @@ namespace Kyoo
.HasForeignKey(x => x.ResourceID) .HasForeignKey(x => x.ResourceID)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
} }
/// <summary>
/// Create a many to many relationship between the two entities.
/// The resulting relationship will have an available <see cref="AddLinks{T1,T2}"/> method.
/// </summary>
/// <param name="modelBuilder">The database model builder</param>
/// <param name="firstNavigation">The first navigation expression from T to T2</param>
/// <param name="secondNavigation">The second navigation expression from T2 to T</param>
/// <typeparam name="T">The owning type of the relationship</typeparam>
/// <typeparam name="T2">The owned type of the relationship</typeparam>
private void _HasManyToMany<T, T2>(ModelBuilder modelBuilder,
Expression<Func<T, IEnumerable<T2>>> firstNavigation,
Expression<Func<T2, IEnumerable<T>>> secondNavigation)
where T : class, IResource
where T2 : class, IResource
{
modelBuilder.Entity<T2>()
.HasMany(secondNavigation)
.WithMany(firstNavigation)
.UsingEntity<Dictionary<string, object>>(
LinkName<T, T2>(),
x => x
.HasOne<T>()
.WithMany()
.HasForeignKey(LinkNameFk<T>())
.OnDelete(DeleteBehavior.Cascade),
x => x
.HasOne<T2>()
.WithMany()
.HasForeignKey(LinkNameFk<T2>())
.OnDelete(DeleteBehavior.Cascade)
);
}
/// <summary> /// <summary>
@ -203,26 +251,12 @@ namespace Kyoo
.WithMany(x => x.Shows) .WithMany(x => x.Shows)
.OnDelete(DeleteBehavior.SetNull); .OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Provider>() _HasManyToMany<Library, Provider>(modelBuilder, x => x.Providers, x => x.Libraries);
.HasMany(x => x.Libraries) _HasManyToMany<Library, Collection>(modelBuilder, x => x.Collections, x => x.Libraries);
.WithMany(x => x.Providers) _HasManyToMany<Library, Show>(modelBuilder, x => x.Shows, x => x.Libraries);
.UsingEntity(x => x.ToTable(LinkName<Library, Provider>())); _HasManyToMany<Collection, Show>(modelBuilder, x => x.Shows, x => x.Collections);
modelBuilder.Entity<Collection>() _HasManyToMany<Show, Genre>(modelBuilder, x => x.Genres, x => x.Shows);
.HasMany(x => x.Libraries)
.WithMany(x => x.Collections)
.UsingEntity(x => x.ToTable(LinkName<Library, Collection>()));
modelBuilder.Entity<Show>()
.HasMany(x => x.Libraries)
.WithMany(x => x.Shows)
.UsingEntity(x => x.ToTable(LinkName<Library, Show>()));
modelBuilder.Entity<Show>()
.HasMany(x => x.Collections)
.WithMany(x => x.Shows)
.UsingEntity(x => x.ToTable(LinkName<Collection, Show>()));
modelBuilder.Entity<Genre>()
.HasMany(x => x.Shows)
.WithMany(x => x.Genres)
.UsingEntity(x => x.ToTable(LinkName<Show, Genre>()));
modelBuilder.Entity<User>() modelBuilder.Entity<User>()
.HasMany(x => x.Watched) .HasMany(x => x.Watched)
.WithMany("Users") .WithMany("Users")

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations namespace Kyoo.Postgresql.Migrations
{ {
[DbContext(typeof(PostgresContext))] [DbContext(typeof(PostgresContext))]
[Migration("20210730183548_Initial")] [Migration("20210801171613_Initial")]
partial class Initial partial class Initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -26,63 +26,6 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "5.0.8") .HasAnnotation("ProductVersion", "5.0.8")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.HasKey("CollectionsID", "LibrariesID")
.HasName("pk_link_library_collection");
b.HasIndex("LibrariesID")
.HasDatabaseName("ix_link_library_collection_libraries_id");
b.ToTable("link_library_collection");
});
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("CollectionsID", "ShowsID")
.HasName("pk_link_collection_show");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_collection_show_shows_id");
b.ToTable("link_collection_show");
});
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("integer")
.HasColumnName("genres_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("GenresID", "ShowsID")
.HasName("pk_link_show_genre");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_show_genre_shows_id");
b.ToTable("link_show_genre");
});
modelBuilder.Entity("Kyoo.Models.Collection", b => modelBuilder.Entity("Kyoo.Models.Collection", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
@ -674,44 +617,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("watched_episodes"); b.ToTable("watched_episodes");
}); });
modelBuilder.Entity("LibraryProvider", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.Property<int>("ProvidersID")
.HasColumnType("integer")
.HasColumnName("providers_id");
b.HasKey("LibrariesID", "ProvidersID")
.HasName("pk_link_library_provider");
b.HasIndex("ProvidersID")
.HasDatabaseName("ix_link_library_provider_providers_id");
b.ToTable("link_library_provider");
});
modelBuilder.Entity("LibraryShow", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("LibrariesID", "ShowsID")
.HasName("pk_link_library_show");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_library_show_shows_id");
b.ToTable("link_library_show");
});
modelBuilder.Entity("ShowUser", b => modelBuilder.Entity("ShowUser", b =>
{ {
b.Property<int>("UsersID") b.Property<int>("UsersID")
@ -785,6 +690,101 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_metadata_id"); b.ToTable("episode_metadata_id");
}); });
modelBuilder.Entity("link_collection_show", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("collection_id", "show_id")
.HasName("pk_link_collection_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_collection_show_show_id");
b.ToTable("link_collection_show");
});
modelBuilder.Entity("link_library_collection", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.HasKey("collection_id", "library_id")
.HasName("pk_link_library_collection");
b.HasIndex("library_id")
.HasDatabaseName("ix_link_library_collection_library_id");
b.ToTable("link_library_collection");
});
modelBuilder.Entity("link_library_provider", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("provider_id")
.HasColumnType("integer")
.HasColumnName("provider_id");
b.HasKey("library_id", "provider_id")
.HasName("pk_link_library_provider");
b.HasIndex("provider_id")
.HasDatabaseName("ix_link_library_provider_provider_id");
b.ToTable("link_library_provider");
});
modelBuilder.Entity("link_library_show", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("library_id", "show_id")
.HasName("pk_link_library_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_library_show_show_id");
b.ToTable("link_library_show");
});
modelBuilder.Entity("link_show_genre", b =>
{
b.Property<int>("genre_id")
.HasColumnType("integer")
.HasColumnName("genre_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("genre_id", "show_id")
.HasName("pk_link_show_genre");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_show_genre_show_id");
b.ToTable("link_show_genre");
});
modelBuilder.Entity("people_metadata_id", b => modelBuilder.Entity("people_metadata_id", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -893,57 +893,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("studio_metadata_id"); b.ToTable("studio_metadata_id");
}); });
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.HasConstraintName("fk_link_library_collection_collections_collections_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_collection_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.HasConstraintName("fk_link_collection_show_collections_collections_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_collection_show_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.HasConstraintName("fk_link_show_genre_genres_genres_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_show_genre_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b => modelBuilder.Entity("Kyoo.Models.Episode", b =>
{ {
b.HasOne("Kyoo.Models.Season", "Season") b.HasOne("Kyoo.Models.Season", "Season")
@ -1039,40 +988,6 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Episode"); b.Navigation("Episode");
}); });
modelBuilder.Entity("LibraryProvider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_provider_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProvidersID")
.HasConstraintName("fk_link_library_provider_providers_providers_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_show_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_library_show_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ShowUser", b => modelBuilder.Entity("ShowUser", b =>
{ {
b.HasOne("Kyoo.Models.User", null) b.HasOne("Kyoo.Models.User", null)
@ -1128,6 +1043,91 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("link_collection_show", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.HasConstraintName("fk_link_collection_show_collections_collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_collection_show_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_collection", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.HasConstraintName("fk_link_library_collection_collections_collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_collection_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_provider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_provider_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("provider_id")
.HasConstraintName("fk_link_library_provider_providers_provider_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_show", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_show_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_library_show_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_show_genre", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("genre_id")
.HasConstraintName("fk_link_show_genre_genres_genre_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_show_genre_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("people_metadata_id", b => modelBuilder.Entity("people_metadata_id", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")

View File

@ -127,21 +127,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_library_collection", name: "link_library_collection",
columns: table => new columns: table => new
{ {
collections_id = table.Column<int>(type: "integer", nullable: false), collection_id = table.Column<int>(type: "integer", nullable: false),
libraries_id = table.Column<int>(type: "integer", nullable: false) library_id = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("pk_link_library_collection", x => new { x.collections_id, x.libraries_id }); table.PrimaryKey("pk_link_library_collection", x => new { x.collection_id, x.library_id });
table.ForeignKey( table.ForeignKey(
name: "fk_link_library_collection_collections_collections_id", name: "fk_link_library_collection_collections_collection_id",
column: x => x.collections_id, column: x => x.collection_id,
principalTable: "collections", principalTable: "collections",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "fk_link_library_collection_libraries_libraries_id", name: "fk_link_library_collection_libraries_library_id",
column: x => x.libraries_id, column: x => x.library_id,
principalTable: "libraries", principalTable: "libraries",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -177,21 +177,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_library_provider", name: "link_library_provider",
columns: table => new columns: table => new
{ {
libraries_id = table.Column<int>(type: "integer", nullable: false), library_id = table.Column<int>(type: "integer", nullable: false),
providers_id = table.Column<int>(type: "integer", nullable: false) provider_id = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("pk_link_library_provider", x => new { x.libraries_id, x.providers_id }); table.PrimaryKey("pk_link_library_provider", x => new { x.library_id, x.provider_id });
table.ForeignKey( table.ForeignKey(
name: "fk_link_library_provider_libraries_libraries_id", name: "fk_link_library_provider_libraries_library_id",
column: x => x.libraries_id, column: x => x.library_id,
principalTable: "libraries", principalTable: "libraries",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "fk_link_library_provider_providers_providers_id", name: "fk_link_library_provider_providers_provider_id",
column: x => x.providers_id, column: x => x.provider_id,
principalTable: "providers", principalTable: "providers",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -282,21 +282,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_collection_show", name: "link_collection_show",
columns: table => new columns: table => new
{ {
collections_id = table.Column<int>(type: "integer", nullable: false), collection_id = table.Column<int>(type: "integer", nullable: false),
shows_id = table.Column<int>(type: "integer", nullable: false) show_id = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("pk_link_collection_show", x => new { x.collections_id, x.shows_id }); table.PrimaryKey("pk_link_collection_show", x => new { x.collection_id, x.show_id });
table.ForeignKey( table.ForeignKey(
name: "fk_link_collection_show_collections_collections_id", name: "fk_link_collection_show_collections_collection_id",
column: x => x.collections_id, column: x => x.collection_id,
principalTable: "collections", principalTable: "collections",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "fk_link_collection_show_shows_shows_id", name: "fk_link_collection_show_shows_show_id",
column: x => x.shows_id, column: x => x.show_id,
principalTable: "shows", principalTable: "shows",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -306,21 +306,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_library_show", name: "link_library_show",
columns: table => new columns: table => new
{ {
libraries_id = table.Column<int>(type: "integer", nullable: false), library_id = table.Column<int>(type: "integer", nullable: false),
shows_id = table.Column<int>(type: "integer", nullable: false) show_id = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("pk_link_library_show", x => new { x.libraries_id, x.shows_id }); table.PrimaryKey("pk_link_library_show", x => new { x.library_id, x.show_id });
table.ForeignKey( table.ForeignKey(
name: "fk_link_library_show_libraries_libraries_id", name: "fk_link_library_show_libraries_library_id",
column: x => x.libraries_id, column: x => x.library_id,
principalTable: "libraries", principalTable: "libraries",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "fk_link_library_show_shows_shows_id", name: "fk_link_library_show_shows_show_id",
column: x => x.shows_id, column: x => x.show_id,
principalTable: "shows", principalTable: "shows",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -330,21 +330,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_show_genre", name: "link_show_genre",
columns: table => new columns: table => new
{ {
genres_id = table.Column<int>(type: "integer", nullable: false), genre_id = table.Column<int>(type: "integer", nullable: false),
shows_id = table.Column<int>(type: "integer", nullable: false) show_id = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("pk_link_show_genre", x => new { x.genres_id, x.shows_id }); table.PrimaryKey("pk_link_show_genre", x => new { x.genre_id, x.show_id });
table.ForeignKey( table.ForeignKey(
name: "fk_link_show_genre_genres_genres_id", name: "fk_link_show_genre_genres_genre_id",
column: x => x.genres_id, column: x => x.genre_id,
principalTable: "genres", principalTable: "genres",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "fk_link_show_genre_shows_shows_id", name: "fk_link_show_genre_shows_show_id",
column: x => x.shows_id, column: x => x.show_id,
principalTable: "shows", principalTable: "shows",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -641,29 +641,29 @@ namespace Kyoo.Postgresql.Migrations
unique: true); unique: true);
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "ix_link_collection_show_shows_id", name: "ix_link_collection_show_show_id",
table: "link_collection_show", table: "link_collection_show",
column: "shows_id"); column: "show_id");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "ix_link_library_collection_libraries_id", name: "ix_link_library_collection_library_id",
table: "link_library_collection", table: "link_library_collection",
column: "libraries_id"); column: "library_id");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "ix_link_library_provider_providers_id", name: "ix_link_library_provider_provider_id",
table: "link_library_provider", table: "link_library_provider",
column: "providers_id"); column: "provider_id");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "ix_link_library_show_shows_id", name: "ix_link_library_show_show_id",
table: "link_library_show", table: "link_library_show",
column: "shows_id"); column: "show_id");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "ix_link_show_genre_shows_id", name: "ix_link_show_genre_show_id",
table: "link_show_genre", table: "link_show_genre",
column: "shows_id"); column: "show_id");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "ix_link_user_show_watched_id", name: "ix_link_user_show_watched_id",

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations namespace Kyoo.Postgresql.Migrations
{ {
[DbContext(typeof(PostgresContext))] [DbContext(typeof(PostgresContext))]
[Migration("20210730203102_Triggers")] [Migration("20210801171641_Triggers")]
partial class Triggers partial class Triggers
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -26,63 +26,6 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "5.0.8") .HasAnnotation("ProductVersion", "5.0.8")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.HasKey("CollectionsID", "LibrariesID")
.HasName("pk_link_library_collection");
b.HasIndex("LibrariesID")
.HasDatabaseName("ix_link_library_collection_libraries_id");
b.ToTable("link_library_collection");
});
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("CollectionsID", "ShowsID")
.HasName("pk_link_collection_show");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_collection_show_shows_id");
b.ToTable("link_collection_show");
});
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("integer")
.HasColumnName("genres_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("GenresID", "ShowsID")
.HasName("pk_link_show_genre");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_show_genre_shows_id");
b.ToTable("link_show_genre");
});
modelBuilder.Entity("Kyoo.Models.Collection", b => modelBuilder.Entity("Kyoo.Models.Collection", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
@ -674,44 +617,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("watched_episodes"); b.ToTable("watched_episodes");
}); });
modelBuilder.Entity("LibraryProvider", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.Property<int>("ProvidersID")
.HasColumnType("integer")
.HasColumnName("providers_id");
b.HasKey("LibrariesID", "ProvidersID")
.HasName("pk_link_library_provider");
b.HasIndex("ProvidersID")
.HasDatabaseName("ix_link_library_provider_providers_id");
b.ToTable("link_library_provider");
});
modelBuilder.Entity("LibraryShow", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("LibrariesID", "ShowsID")
.HasName("pk_link_library_show");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_library_show_shows_id");
b.ToTable("link_library_show");
});
modelBuilder.Entity("ShowUser", b => modelBuilder.Entity("ShowUser", b =>
{ {
b.Property<int>("UsersID") b.Property<int>("UsersID")
@ -785,6 +690,101 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_metadata_id"); b.ToTable("episode_metadata_id");
}); });
modelBuilder.Entity("link_collection_show", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("collection_id", "show_id")
.HasName("pk_link_collection_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_collection_show_show_id");
b.ToTable("link_collection_show");
});
modelBuilder.Entity("link_library_collection", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.HasKey("collection_id", "library_id")
.HasName("pk_link_library_collection");
b.HasIndex("library_id")
.HasDatabaseName("ix_link_library_collection_library_id");
b.ToTable("link_library_collection");
});
modelBuilder.Entity("link_library_provider", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("provider_id")
.HasColumnType("integer")
.HasColumnName("provider_id");
b.HasKey("library_id", "provider_id")
.HasName("pk_link_library_provider");
b.HasIndex("provider_id")
.HasDatabaseName("ix_link_library_provider_provider_id");
b.ToTable("link_library_provider");
});
modelBuilder.Entity("link_library_show", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("library_id", "show_id")
.HasName("pk_link_library_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_library_show_show_id");
b.ToTable("link_library_show");
});
modelBuilder.Entity("link_show_genre", b =>
{
b.Property<int>("genre_id")
.HasColumnType("integer")
.HasColumnName("genre_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("genre_id", "show_id")
.HasName("pk_link_show_genre");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_show_genre_show_id");
b.ToTable("link_show_genre");
});
modelBuilder.Entity("people_metadata_id", b => modelBuilder.Entity("people_metadata_id", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -893,57 +893,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("studio_metadata_id"); b.ToTable("studio_metadata_id");
}); });
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.HasConstraintName("fk_link_library_collection_collections_collections_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_collection_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.HasConstraintName("fk_link_collection_show_collections_collections_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_collection_show_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.HasConstraintName("fk_link_show_genre_genres_genres_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_show_genre_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b => modelBuilder.Entity("Kyoo.Models.Episode", b =>
{ {
b.HasOne("Kyoo.Models.Season", "Season") b.HasOne("Kyoo.Models.Season", "Season")
@ -1039,40 +988,6 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Episode"); b.Navigation("Episode");
}); });
modelBuilder.Entity("LibraryProvider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_provider_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProvidersID")
.HasConstraintName("fk_link_library_provider_providers_providers_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_show_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_library_show_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ShowUser", b => modelBuilder.Entity("ShowUser", b =>
{ {
b.HasOne("Kyoo.Models.User", null) b.HasOne("Kyoo.Models.User", null)
@ -1128,6 +1043,91 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("link_collection_show", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.HasConstraintName("fk_link_collection_show_collections_collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_collection_show_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_collection", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.HasConstraintName("fk_link_library_collection_collections_collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_collection_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_provider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_provider_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("provider_id")
.HasConstraintName("fk_link_library_provider_providers_provider_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_show", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_show_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_library_show_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_show_genre", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("genre_id")
.HasConstraintName("fk_link_show_genre_genres_genre_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_show_genre_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("people_metadata_id", b => modelBuilder.Entity("people_metadata_id", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")

View File

@ -149,8 +149,8 @@ namespace Kyoo.Postgresql.Migrations
WHERE NOT (EXISTS ( WHERE NOT (EXISTS (
SELECT 1 SELECT 1
FROM link_collection_show AS l FROM link_collection_show AS l
INNER JOIN collections AS c ON l.collections_id = c.id INNER JOIN collections AS c ON l.collection_id = c.id
WHERE s.id = l.shows_id)) WHERE s.id = l.show_id))
UNION ALL UNION ALL
SELECT -c0.id, c0.slug, c0.name AS title, c0.overview, 'unknown'::status AS status, SELECT -c0.id, c0.slug, c0.name AS title, c0.overview, 'unknown'::status AS status,
NULL AS start_air, NULL AS end_air, c0.images, 'collection'::item_type AS type NULL AS start_air, NULL AS end_air, c0.images, 'collection'::item_type AS type

View File

@ -24,63 +24,6 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "5.0.8") .HasAnnotation("ProductVersion", "5.0.8")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.HasKey("CollectionsID", "LibrariesID")
.HasName("pk_link_library_collection");
b.HasIndex("LibrariesID")
.HasDatabaseName("ix_link_library_collection_libraries_id");
b.ToTable("link_library_collection");
});
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer")
.HasColumnName("collections_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("CollectionsID", "ShowsID")
.HasName("pk_link_collection_show");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_collection_show_shows_id");
b.ToTable("link_collection_show");
});
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("integer")
.HasColumnName("genres_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("GenresID", "ShowsID")
.HasName("pk_link_show_genre");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_show_genre_shows_id");
b.ToTable("link_show_genre");
});
modelBuilder.Entity("Kyoo.Models.Collection", b => modelBuilder.Entity("Kyoo.Models.Collection", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
@ -672,44 +615,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("watched_episodes"); b.ToTable("watched_episodes");
}); });
modelBuilder.Entity("LibraryProvider", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.Property<int>("ProvidersID")
.HasColumnType("integer")
.HasColumnName("providers_id");
b.HasKey("LibrariesID", "ProvidersID")
.HasName("pk_link_library_provider");
b.HasIndex("ProvidersID")
.HasDatabaseName("ix_link_library_provider_providers_id");
b.ToTable("link_library_provider");
});
modelBuilder.Entity("LibraryShow", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer")
.HasColumnName("libraries_id");
b.Property<int>("ShowsID")
.HasColumnType("integer")
.HasColumnName("shows_id");
b.HasKey("LibrariesID", "ShowsID")
.HasName("pk_link_library_show");
b.HasIndex("ShowsID")
.HasDatabaseName("ix_link_library_show_shows_id");
b.ToTable("link_library_show");
});
modelBuilder.Entity("ShowUser", b => modelBuilder.Entity("ShowUser", b =>
{ {
b.Property<int>("UsersID") b.Property<int>("UsersID")
@ -783,6 +688,101 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_metadata_id"); b.ToTable("episode_metadata_id");
}); });
modelBuilder.Entity("link_collection_show", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("collection_id", "show_id")
.HasName("pk_link_collection_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_collection_show_show_id");
b.ToTable("link_collection_show");
});
modelBuilder.Entity("link_library_collection", b =>
{
b.Property<int>("collection_id")
.HasColumnType("integer")
.HasColumnName("collection_id");
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.HasKey("collection_id", "library_id")
.HasName("pk_link_library_collection");
b.HasIndex("library_id")
.HasDatabaseName("ix_link_library_collection_library_id");
b.ToTable("link_library_collection");
});
modelBuilder.Entity("link_library_provider", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("provider_id")
.HasColumnType("integer")
.HasColumnName("provider_id");
b.HasKey("library_id", "provider_id")
.HasName("pk_link_library_provider");
b.HasIndex("provider_id")
.HasDatabaseName("ix_link_library_provider_provider_id");
b.ToTable("link_library_provider");
});
modelBuilder.Entity("link_library_show", b =>
{
b.Property<int>("library_id")
.HasColumnType("integer")
.HasColumnName("library_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("library_id", "show_id")
.HasName("pk_link_library_show");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_library_show_show_id");
b.ToTable("link_library_show");
});
modelBuilder.Entity("link_show_genre", b =>
{
b.Property<int>("genre_id")
.HasColumnType("integer")
.HasColumnName("genre_id");
b.Property<int>("show_id")
.HasColumnType("integer")
.HasColumnName("show_id");
b.HasKey("genre_id", "show_id")
.HasName("pk_link_show_genre");
b.HasIndex("show_id")
.HasDatabaseName("ix_link_show_genre_show_id");
b.ToTable("link_show_genre");
});
modelBuilder.Entity("people_metadata_id", b => modelBuilder.Entity("people_metadata_id", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -891,57 +891,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("studio_metadata_id"); b.ToTable("studio_metadata_id");
}); });
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.HasConstraintName("fk_link_library_collection_collections_collections_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_collection_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.HasConstraintName("fk_link_collection_show_collections_collections_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_collection_show_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.HasConstraintName("fk_link_show_genre_genres_genres_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_show_genre_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b => modelBuilder.Entity("Kyoo.Models.Episode", b =>
{ {
b.HasOne("Kyoo.Models.Season", "Season") b.HasOne("Kyoo.Models.Season", "Season")
@ -1037,40 +986,6 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Episode"); b.Navigation("Episode");
}); });
modelBuilder.Entity("LibraryProvider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_provider_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProvidersID")
.HasConstraintName("fk_link_library_provider_providers_providers_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.HasConstraintName("fk_link_library_show_libraries_libraries_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.HasConstraintName("fk_link_library_show_shows_shows_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ShowUser", b => modelBuilder.Entity("ShowUser", b =>
{ {
b.HasOne("Kyoo.Models.User", null) b.HasOne("Kyoo.Models.User", null)
@ -1126,6 +1041,91 @@ namespace Kyoo.Postgresql.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("link_collection_show", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.HasConstraintName("fk_link_collection_show_collections_collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_collection_show_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_collection", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("collection_id")
.HasConstraintName("fk_link_library_collection_collections_collection_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_collection_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_provider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_provider_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("provider_id")
.HasConstraintName("fk_link_library_provider_providers_provider_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_library_show", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("library_id")
.HasConstraintName("fk_link_library_show_libraries_library_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_library_show_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("link_show_genre", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("genre_id")
.HasConstraintName("fk_link_show_genre_genres_genre_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("show_id")
.HasConstraintName("fk_link_show_genre_shows_show_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("people_metadata_id", b => modelBuilder.Entity("people_metadata_id", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")

View File

@ -142,6 +142,13 @@ namespace Kyoo.Postgresql
SnakeCaseNameRewriter rewriter = new(CultureInfo.InvariantCulture); SnakeCaseNameRewriter rewriter = new(CultureInfo.InvariantCulture);
return rewriter.RewriteName("Link" + typeof(T).Name + typeof(T2).Name); return rewriter.RewriteName("Link" + typeof(T).Name + typeof(T2).Name);
} }
/// <inheritdoc />
protected override string LinkNameFk<T>()
{
SnakeCaseNameRewriter rewriter = new(CultureInfo.InvariantCulture);
return rewriter.RewriteName(typeof(T).Name + "ID");
}
/// <inheritdoc /> /// <inheritdoc />
protected override bool IsDuplicateException(Exception ex) protected override bool IsDuplicateException(Exception ex)

View File

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.SqLite.Migrations namespace Kyoo.SqLite.Migrations
{ {
[DbContext(typeof(SqLiteContext))] [DbContext(typeof(SqLiteContext))]
[Migration("20210730203155_Initial")] [Migration("20210801171534_Initial")]
partial class Initial partial class Initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -18,21 +18,6 @@ namespace Kyoo.SqLite.Migrations
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "5.0.8"); .HasAnnotation("ProductVersion", "5.0.8");
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("INTEGER");
b.Property<int>("LibrariesID")
.HasColumnType("INTEGER");
b.HasKey("CollectionsID", "LibrariesID");
b.HasIndex("LibrariesID");
b.ToTable("LinkLibraryCollection");
});
modelBuilder.Entity("CollectionMetadataID", b => modelBuilder.Entity("CollectionMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -54,21 +39,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("CollectionMetadataID"); b.ToTable("CollectionMetadataID");
}); });
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("INTEGER");
b.Property<int>("ShowsID")
.HasColumnType("INTEGER");
b.HasKey("CollectionsID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LinkCollectionShow");
});
modelBuilder.Entity("EpisodeMetadataID", b => modelBuilder.Entity("EpisodeMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -90,21 +60,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("EpisodeMetadataID"); b.ToTable("EpisodeMetadataID");
}); });
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("INTEGER");
b.Property<int>("ShowsID")
.HasColumnType("INTEGER");
b.HasKey("GenresID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LinkShowGenre");
});
modelBuilder.Entity("Kyoo.Models.Collection", b => modelBuilder.Entity("Kyoo.Models.Collection", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
@ -558,36 +513,81 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("WatchedEpisodes"); b.ToTable("WatchedEpisodes");
}); });
modelBuilder.Entity("LibraryProvider", b => modelBuilder.Entity("LinkCollectionShow", b =>
{ {
b.Property<int>("LibrariesID") b.Property<int>("CollectionID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("ProvidersID") b.Property<int>("ShowID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("LibrariesID", "ProvidersID"); b.HasKey("CollectionID", "ShowID");
b.HasIndex("ProvidersID"); b.HasIndex("ShowID");
b.ToTable("LinkCollectionShow");
});
modelBuilder.Entity("LinkLibraryCollection", b =>
{
b.Property<int>("CollectionID")
.HasColumnType("INTEGER");
b.Property<int>("LibraryID")
.HasColumnType("INTEGER");
b.HasKey("CollectionID", "LibraryID");
b.HasIndex("LibraryID");
b.ToTable("LinkLibraryCollection");
});
modelBuilder.Entity("LinkLibraryProvider", b =>
{
b.Property<int>("LibraryID")
.HasColumnType("INTEGER");
b.Property<int>("ProviderID")
.HasColumnType("INTEGER");
b.HasKey("LibraryID", "ProviderID");
b.HasIndex("ProviderID");
b.ToTable("LinkLibraryProvider"); b.ToTable("LinkLibraryProvider");
}); });
modelBuilder.Entity("LibraryShow", b => modelBuilder.Entity("LinkLibraryShow", b =>
{ {
b.Property<int>("LibrariesID") b.Property<int>("LibraryID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("ShowsID") b.Property<int>("ShowID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("LibrariesID", "ShowsID"); b.HasKey("LibraryID", "ShowID");
b.HasIndex("ShowsID"); b.HasIndex("ShowID");
b.ToTable("LinkLibraryShow"); b.ToTable("LinkLibraryShow");
}); });
modelBuilder.Entity("LinkShowGenre", b =>
{
b.Property<int>("GenreID")
.HasColumnType("INTEGER");
b.Property<int>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("GenreID", "ShowID");
b.HasIndex("ShowID");
b.ToTable("LinkShowGenre");
});
modelBuilder.Entity("PeopleMetadataID", b => modelBuilder.Entity("PeopleMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -687,21 +687,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("StudioMetadataID"); b.ToTable("StudioMetadataID");
}); });
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionMetadataID", b => modelBuilder.Entity("CollectionMetadataID", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")
@ -719,21 +704,6 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EpisodeMetadataID", b => modelBuilder.Entity("EpisodeMetadataID", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")
@ -751,21 +721,6 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b => modelBuilder.Entity("Kyoo.Models.Episode", b =>
{ {
b.HasOne("Kyoo.Models.Season", "Season") b.HasOne("Kyoo.Models.Season", "Season")
@ -852,32 +807,77 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Episode"); b.Navigation("Episode");
}); });
modelBuilder.Entity("LibraryProvider", b => modelBuilder.Entity("LinkCollectionShow", b =>
{ {
b.HasOne("Kyoo.Models.Library", null) b.HasOne("Kyoo.Models.Collection", null)
.WithMany() .WithMany()
.HasForeignKey("LibrariesID") .HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProvidersID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Kyoo.Models.Show", null) b.HasOne("Kyoo.Models.Show", null)
.WithMany() .WithMany()
.HasForeignKey("ShowsID") .HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryCollection", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryProvider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkShowGenre", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenreID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });

View File

@ -119,21 +119,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkLibraryCollection", name: "LinkLibraryCollection",
columns: table => new columns: table => new
{ {
CollectionsID = table.Column<int>(type: "INTEGER", nullable: false), CollectionID = table.Column<int>(type: "INTEGER", nullable: false),
LibrariesID = table.Column<int>(type: "INTEGER", nullable: false) LibraryID = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_LinkLibraryCollection", x => new { x.CollectionsID, x.LibrariesID }); table.PrimaryKey("PK_LinkLibraryCollection", x => new { x.CollectionID, x.LibraryID });
table.ForeignKey( table.ForeignKey(
name: "FK_LinkLibraryCollection_Collections_CollectionsID", name: "FK_LinkLibraryCollection_Collections_CollectionID",
column: x => x.CollectionsID, column: x => x.CollectionID,
principalTable: "Collections", principalTable: "Collections",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_LinkLibraryCollection_Libraries_LibrariesID", name: "FK_LinkLibraryCollection_Libraries_LibraryID",
column: x => x.LibrariesID, column: x => x.LibraryID,
principalTable: "Libraries", principalTable: "Libraries",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -169,21 +169,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkLibraryProvider", name: "LinkLibraryProvider",
columns: table => new columns: table => new
{ {
LibrariesID = table.Column<int>(type: "INTEGER", nullable: false), LibraryID = table.Column<int>(type: "INTEGER", nullable: false),
ProvidersID = table.Column<int>(type: "INTEGER", nullable: false) ProviderID = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_LinkLibraryProvider", x => new { x.LibrariesID, x.ProvidersID }); table.PrimaryKey("PK_LinkLibraryProvider", x => new { x.LibraryID, x.ProviderID });
table.ForeignKey( table.ForeignKey(
name: "FK_LinkLibraryProvider_Libraries_LibrariesID", name: "FK_LinkLibraryProvider_Libraries_LibraryID",
column: x => x.LibrariesID, column: x => x.LibraryID,
principalTable: "Libraries", principalTable: "Libraries",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_LinkLibraryProvider_Providers_ProvidersID", name: "FK_LinkLibraryProvider_Providers_ProviderID",
column: x => x.ProvidersID, column: x => x.ProviderID,
principalTable: "Providers", principalTable: "Providers",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -274,21 +274,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkCollectionShow", name: "LinkCollectionShow",
columns: table => new columns: table => new
{ {
CollectionsID = table.Column<int>(type: "INTEGER", nullable: false), CollectionID = table.Column<int>(type: "INTEGER", nullable: false),
ShowsID = table.Column<int>(type: "INTEGER", nullable: false) ShowID = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_LinkCollectionShow", x => new { x.CollectionsID, x.ShowsID }); table.PrimaryKey("PK_LinkCollectionShow", x => new { x.CollectionID, x.ShowID });
table.ForeignKey( table.ForeignKey(
name: "FK_LinkCollectionShow_Collections_CollectionsID", name: "FK_LinkCollectionShow_Collections_CollectionID",
column: x => x.CollectionsID, column: x => x.CollectionID,
principalTable: "Collections", principalTable: "Collections",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_LinkCollectionShow_Shows_ShowsID", name: "FK_LinkCollectionShow_Shows_ShowID",
column: x => x.ShowsID, column: x => x.ShowID,
principalTable: "Shows", principalTable: "Shows",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -298,21 +298,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkLibraryShow", name: "LinkLibraryShow",
columns: table => new columns: table => new
{ {
LibrariesID = table.Column<int>(type: "INTEGER", nullable: false), LibraryID = table.Column<int>(type: "INTEGER", nullable: false),
ShowsID = table.Column<int>(type: "INTEGER", nullable: false) ShowID = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_LinkLibraryShow", x => new { x.LibrariesID, x.ShowsID }); table.PrimaryKey("PK_LinkLibraryShow", x => new { x.LibraryID, x.ShowID });
table.ForeignKey( table.ForeignKey(
name: "FK_LinkLibraryShow_Libraries_LibrariesID", name: "FK_LinkLibraryShow_Libraries_LibraryID",
column: x => x.LibrariesID, column: x => x.LibraryID,
principalTable: "Libraries", principalTable: "Libraries",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_LinkLibraryShow_Shows_ShowsID", name: "FK_LinkLibraryShow_Shows_ShowID",
column: x => x.ShowsID, column: x => x.ShowID,
principalTable: "Shows", principalTable: "Shows",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -322,21 +322,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkShowGenre", name: "LinkShowGenre",
columns: table => new columns: table => new
{ {
GenresID = table.Column<int>(type: "INTEGER", nullable: false), GenreID = table.Column<int>(type: "INTEGER", nullable: false),
ShowsID = table.Column<int>(type: "INTEGER", nullable: false) ShowID = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_LinkShowGenre", x => new { x.GenresID, x.ShowsID }); table.PrimaryKey("PK_LinkShowGenre", x => new { x.GenreID, x.ShowID });
table.ForeignKey( table.ForeignKey(
name: "FK_LinkShowGenre_Genres_GenresID", name: "FK_LinkShowGenre_Genres_GenreID",
column: x => x.GenresID, column: x => x.GenreID,
principalTable: "Genres", principalTable: "Genres",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_LinkShowGenre_Shows_ShowsID", name: "FK_LinkShowGenre_Shows_ShowID",
column: x => x.ShowsID, column: x => x.ShowID,
principalTable: "Shows", principalTable: "Shows",
principalColumn: "ID", principalColumn: "ID",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -633,29 +633,29 @@ namespace Kyoo.SqLite.Migrations
unique: true); unique: true);
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_LinkCollectionShow_ShowsID", name: "IX_LinkCollectionShow_ShowID",
table: "LinkCollectionShow", table: "LinkCollectionShow",
column: "ShowsID"); column: "ShowID");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_LinkLibraryCollection_LibrariesID", name: "IX_LinkLibraryCollection_LibraryID",
table: "LinkLibraryCollection", table: "LinkLibraryCollection",
column: "LibrariesID"); column: "LibraryID");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_LinkLibraryProvider_ProvidersID", name: "IX_LinkLibraryProvider_ProviderID",
table: "LinkLibraryProvider", table: "LinkLibraryProvider",
column: "ProvidersID"); column: "ProviderID");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_LinkLibraryShow_ShowsID", name: "IX_LinkLibraryShow_ShowID",
table: "LinkLibraryShow", table: "LinkLibraryShow",
column: "ShowsID"); column: "ShowID");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_LinkShowGenre_ShowsID", name: "IX_LinkShowGenre_ShowID",
table: "LinkShowGenre", table: "LinkShowGenre",
column: "ShowsID"); column: "ShowID");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_LinkUserShow_WatchedID", name: "IX_LinkUserShow_WatchedID",

View File

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.SqLite.Migrations namespace Kyoo.SqLite.Migrations
{ {
[DbContext(typeof(SqLiteContext))] [DbContext(typeof(SqLiteContext))]
[Migration("20210730203746_Triggers")] [Migration("20210801171544_Triggers")]
partial class Triggers partial class Triggers
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -18,21 +18,6 @@ namespace Kyoo.SqLite.Migrations
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "5.0.8"); .HasAnnotation("ProductVersion", "5.0.8");
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("INTEGER");
b.Property<int>("LibrariesID")
.HasColumnType("INTEGER");
b.HasKey("CollectionsID", "LibrariesID");
b.HasIndex("LibrariesID");
b.ToTable("LinkLibraryCollection");
});
modelBuilder.Entity("CollectionMetadataID", b => modelBuilder.Entity("CollectionMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -54,21 +39,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("CollectionMetadataID"); b.ToTable("CollectionMetadataID");
}); });
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("INTEGER");
b.Property<int>("ShowsID")
.HasColumnType("INTEGER");
b.HasKey("CollectionsID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LinkCollectionShow");
});
modelBuilder.Entity("EpisodeMetadataID", b => modelBuilder.Entity("EpisodeMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -90,21 +60,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("EpisodeMetadataID"); b.ToTable("EpisodeMetadataID");
}); });
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("INTEGER");
b.Property<int>("ShowsID")
.HasColumnType("INTEGER");
b.HasKey("GenresID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LinkShowGenre");
});
modelBuilder.Entity("Kyoo.Models.Collection", b => modelBuilder.Entity("Kyoo.Models.Collection", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
@ -558,36 +513,81 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("WatchedEpisodes"); b.ToTable("WatchedEpisodes");
}); });
modelBuilder.Entity("LibraryProvider", b => modelBuilder.Entity("LinkCollectionShow", b =>
{ {
b.Property<int>("LibrariesID") b.Property<int>("CollectionID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("ProvidersID") b.Property<int>("ShowID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("LibrariesID", "ProvidersID"); b.HasKey("CollectionID", "ShowID");
b.HasIndex("ProvidersID"); b.HasIndex("ShowID");
b.ToTable("LinkCollectionShow");
});
modelBuilder.Entity("LinkLibraryCollection", b =>
{
b.Property<int>("CollectionID")
.HasColumnType("INTEGER");
b.Property<int>("LibraryID")
.HasColumnType("INTEGER");
b.HasKey("CollectionID", "LibraryID");
b.HasIndex("LibraryID");
b.ToTable("LinkLibraryCollection");
});
modelBuilder.Entity("LinkLibraryProvider", b =>
{
b.Property<int>("LibraryID")
.HasColumnType("INTEGER");
b.Property<int>("ProviderID")
.HasColumnType("INTEGER");
b.HasKey("LibraryID", "ProviderID");
b.HasIndex("ProviderID");
b.ToTable("LinkLibraryProvider"); b.ToTable("LinkLibraryProvider");
}); });
modelBuilder.Entity("LibraryShow", b => modelBuilder.Entity("LinkLibraryShow", b =>
{ {
b.Property<int>("LibrariesID") b.Property<int>("LibraryID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("ShowsID") b.Property<int>("ShowID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("LibrariesID", "ShowsID"); b.HasKey("LibraryID", "ShowID");
b.HasIndex("ShowsID"); b.HasIndex("ShowID");
b.ToTable("LinkLibraryShow"); b.ToTable("LinkLibraryShow");
}); });
modelBuilder.Entity("LinkShowGenre", b =>
{
b.Property<int>("GenreID")
.HasColumnType("INTEGER");
b.Property<int>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("GenreID", "ShowID");
b.HasIndex("ShowID");
b.ToTable("LinkShowGenre");
});
modelBuilder.Entity("PeopleMetadataID", b => modelBuilder.Entity("PeopleMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -687,21 +687,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("StudioMetadataID"); b.ToTable("StudioMetadataID");
}); });
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionMetadataID", b => modelBuilder.Entity("CollectionMetadataID", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")
@ -719,21 +704,6 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EpisodeMetadataID", b => modelBuilder.Entity("EpisodeMetadataID", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")
@ -751,21 +721,6 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b => modelBuilder.Entity("Kyoo.Models.Episode", b =>
{ {
b.HasOne("Kyoo.Models.Season", "Season") b.HasOne("Kyoo.Models.Season", "Season")
@ -852,32 +807,77 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Episode"); b.Navigation("Episode");
}); });
modelBuilder.Entity("LibraryProvider", b => modelBuilder.Entity("LinkCollectionShow", b =>
{ {
b.HasOne("Kyoo.Models.Library", null) b.HasOne("Kyoo.Models.Collection", null)
.WithMany() .WithMany()
.HasForeignKey("LibrariesID") .HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProvidersID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Kyoo.Models.Show", null) b.HasOne("Kyoo.Models.Show", null)
.WithMany() .WithMany()
.HasForeignKey("ShowsID") .HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryCollection", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryProvider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkShowGenre", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenreID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });

View File

@ -162,8 +162,8 @@ namespace Kyoo.SqLite.Migrations
WHERE NOT (EXISTS ( WHERE NOT (EXISTS (
SELECT 1 SELECT 1
FROM LinkCollectionShow AS l FROM LinkCollectionShow AS l
INNER JOIN Collections AS c ON l.CollectionsID = c.ID INNER JOIN Collections AS c ON l.CollectionID = c.ID
WHERE s.ID = l.ShowsID)) WHERE s.ID = l.ShowID))
UNION ALL UNION ALL
SELECT -c0.ID, c0.Slug, c0.Name AS Title, c0.Overview, 0 AS Status, SELECT -c0.ID, c0.Slug, c0.Name AS Title, c0.Overview, 0 AS Status,
NULL AS StartAir, NULL AS EndAir, c0.Images, 2 AS Type NULL AS StartAir, NULL AS EndAir, c0.Images, 2 AS Type

View File

@ -16,21 +16,6 @@ namespace Kyoo.SqLite.Migrations
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "5.0.8"); .HasAnnotation("ProductVersion", "5.0.8");
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("INTEGER");
b.Property<int>("LibrariesID")
.HasColumnType("INTEGER");
b.HasKey("CollectionsID", "LibrariesID");
b.HasIndex("LibrariesID");
b.ToTable("LinkLibraryCollection");
});
modelBuilder.Entity("CollectionMetadataID", b => modelBuilder.Entity("CollectionMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -52,21 +37,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("CollectionMetadataID"); b.ToTable("CollectionMetadataID");
}); });
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("INTEGER");
b.Property<int>("ShowsID")
.HasColumnType("INTEGER");
b.HasKey("CollectionsID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LinkCollectionShow");
});
modelBuilder.Entity("EpisodeMetadataID", b => modelBuilder.Entity("EpisodeMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -88,21 +58,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("EpisodeMetadataID"); b.ToTable("EpisodeMetadataID");
}); });
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("INTEGER");
b.Property<int>("ShowsID")
.HasColumnType("INTEGER");
b.HasKey("GenresID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LinkShowGenre");
});
modelBuilder.Entity("Kyoo.Models.Collection", b => modelBuilder.Entity("Kyoo.Models.Collection", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
@ -556,36 +511,81 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("WatchedEpisodes"); b.ToTable("WatchedEpisodes");
}); });
modelBuilder.Entity("LibraryProvider", b => modelBuilder.Entity("LinkCollectionShow", b =>
{ {
b.Property<int>("LibrariesID") b.Property<int>("CollectionID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("ProvidersID") b.Property<int>("ShowID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("LibrariesID", "ProvidersID"); b.HasKey("CollectionID", "ShowID");
b.HasIndex("ProvidersID"); b.HasIndex("ShowID");
b.ToTable("LinkCollectionShow");
});
modelBuilder.Entity("LinkLibraryCollection", b =>
{
b.Property<int>("CollectionID")
.HasColumnType("INTEGER");
b.Property<int>("LibraryID")
.HasColumnType("INTEGER");
b.HasKey("CollectionID", "LibraryID");
b.HasIndex("LibraryID");
b.ToTable("LinkLibraryCollection");
});
modelBuilder.Entity("LinkLibraryProvider", b =>
{
b.Property<int>("LibraryID")
.HasColumnType("INTEGER");
b.Property<int>("ProviderID")
.HasColumnType("INTEGER");
b.HasKey("LibraryID", "ProviderID");
b.HasIndex("ProviderID");
b.ToTable("LinkLibraryProvider"); b.ToTable("LinkLibraryProvider");
}); });
modelBuilder.Entity("LibraryShow", b => modelBuilder.Entity("LinkLibraryShow", b =>
{ {
b.Property<int>("LibrariesID") b.Property<int>("LibraryID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("ShowsID") b.Property<int>("ShowID")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("LibrariesID", "ShowsID"); b.HasKey("LibraryID", "ShowID");
b.HasIndex("ShowsID"); b.HasIndex("ShowID");
b.ToTable("LinkLibraryShow"); b.ToTable("LinkLibraryShow");
}); });
modelBuilder.Entity("LinkShowGenre", b =>
{
b.Property<int>("GenreID")
.HasColumnType("INTEGER");
b.Property<int>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("GenreID", "ShowID");
b.HasIndex("ShowID");
b.ToTable("LinkShowGenre");
});
modelBuilder.Entity("PeopleMetadataID", b => modelBuilder.Entity("PeopleMetadataID", b =>
{ {
b.Property<int>("ResourceID") b.Property<int>("ResourceID")
@ -685,21 +685,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("StudioMetadataID"); b.ToTable("StudioMetadataID");
}); });
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionMetadataID", b => modelBuilder.Entity("CollectionMetadataID", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")
@ -717,21 +702,6 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EpisodeMetadataID", b => modelBuilder.Entity("EpisodeMetadataID", b =>
{ {
b.HasOne("Kyoo.Models.Provider", "Provider") b.HasOne("Kyoo.Models.Provider", "Provider")
@ -749,21 +719,6 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Provider"); b.Navigation("Provider");
}); });
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b => modelBuilder.Entity("Kyoo.Models.Episode", b =>
{ {
b.HasOne("Kyoo.Models.Season", "Season") b.HasOne("Kyoo.Models.Season", "Season")
@ -850,32 +805,77 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Episode"); b.Navigation("Episode");
}); });
modelBuilder.Entity("LibraryProvider", b => modelBuilder.Entity("LinkCollectionShow", b =>
{ {
b.HasOne("Kyoo.Models.Library", null) b.HasOne("Kyoo.Models.Collection", null)
.WithMany() .WithMany()
.HasForeignKey("LibrariesID") .HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProvidersID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Kyoo.Models.Show", null) b.HasOne("Kyoo.Models.Show", null)
.WithMany() .WithMany()
.HasForeignKey("ShowsID") .HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryCollection", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryProvider", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", null)
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkLibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LinkShowGenre", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenreID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });

View File

@ -155,6 +155,12 @@ namespace Kyoo.SqLite
{ {
return "Link" + typeof(T).Name + typeof(T2).Name; return "Link" + typeof(T).Name + typeof(T2).Name;
} }
/// <inheritdoc />
protected override string LinkNameFk<T>()
{
return typeof(T).Name + "ID";
}
/// <inheritdoc /> /// <inheritdoc />
protected override bool IsDuplicateException(Exception ex) protected override bool IsDuplicateException(Exception ex)

View File

@ -141,12 +141,16 @@ namespace Kyoo.Controllers
/// <returns>The <see cref="resource"/> parameter is returned.</returns> /// <returns>The <see cref="resource"/> parameter is returned.</returns>
private async Task<Episode> ValidateTracks(Episode resource) private async Task<Episode> ValidateTracks(Episode resource)
{ {
resource.Tracks = await TaskUtils.DefaultIfNull(resource.Tracks?.SelectAsync(x => if (resource.Tracks == null)
return resource;
resource.Tracks = await resource.Tracks.SelectAsync(x =>
{ {
x.Episode = resource; x.Episode = resource;
x.EpisodeSlug = resource.Slug; x.EpisodeSlug = resource.Slug;
return _tracks.Create(x); return _tracks.Create(x);
}).ToListAsync()); }).ToListAsync();
_database.Tracks.AttachRange(resource.Tracks);
return resource; return resource;
} }
@ -155,8 +159,12 @@ namespace Kyoo.Controllers
{ {
await base.Validate(resource); await base.Validate(resource);
if (resource.ShowID <= 0) if (resource.ShowID <= 0)
throw new ArgumentException($"Can't store an episode not related " + {
$"to any show (showID: {resource.ShowID})."); if (resource.Show == null)
throw new ArgumentException($"Can't store an episode not related " +
$"to any show (showID: {resource.ShowID}).");
resource.ShowID = resource.Show.ID;
}
if (resource.ExternalIDs != null) if (resource.ExternalIDs != null)
{ {

View File

@ -159,21 +159,18 @@ namespace Kyoo.Controllers
{ {
if (collectionID != null) if (collectionID != null)
{ {
await _database.Links<Collection, Show>() await _database.AddLinks<Collection, Show>(collectionID.Value, showID);
.AddAsync(new Link<Collection, Show>(collectionID.Value, showID));
await _database.SaveIfNoDuplicates(); await _database.SaveIfNoDuplicates();
if (libraryID != null) if (libraryID != null)
{ {
await _database.Links<Library, Collection>() await _database.AddLinks<Library, Collection>(libraryID.Value, collectionID.Value);
.AddAsync(new Link<Library, Collection>(libraryID.Value, collectionID.Value));
await _database.SaveIfNoDuplicates(); await _database.SaveIfNoDuplicates();
} }
} }
if (libraryID != null) if (libraryID != null)
{ {
await _database.Links<Library, Show>() await _database.AddLinks<Library, Show>(libraryID.Value, showID);
.AddAsync(new Link<Library, Show>(libraryID.Value, showID));
await _database.SaveIfNoDuplicates(); await _database.SaveIfNoDuplicates();
} }
} }

View File

@ -360,5 +360,18 @@ namespace Kyoo.Tests.Database
Assert.Equal(0, await Repositories.LibraryManager.SeasonRepository.GetCount()); Assert.Equal(0, await Repositories.LibraryManager.SeasonRepository.GetCount());
Assert.Equal(0, await Repositories.LibraryManager.EpisodeRepository.GetCount()); Assert.Equal(0, await Repositories.LibraryManager.EpisodeRepository.GetCount());
} }
[Fact]
public async Task AddShowLinkTest()
{
await Repositories.LibraryManager.Create(TestSample.GetNew<Library>());
await _repository.AddShowLink(1, 2, null);
await using DatabaseContext context = Repositories.Context.New();
Show show = context.Shows
.Include(x => x.Libraries)
.First(x => x.ID == 1);
Assert.Contains(2, show.Libraries.Select(x => x.ID));
}
} }
} }