diff --git a/Kyoo.Common/Models/Link.cs b/Kyoo.Common/Models/Link.cs
deleted file mode 100644
index 1f4cf4ac..00000000
--- a/Kyoo.Common/Models/Link.cs
+++ /dev/null
@@ -1,163 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using Kyoo.Models.Attributes;
-
-namespace Kyoo.Models
-{
- ///
- /// A class representing a link between two resources.
- ///
- ///
- /// Links should only be used on the data layer and not on other application code.
- ///
- public class Link
- {
- ///
- /// The ID of the first item of the link.
- /// The first item of the link should be the one to own the link.
- ///
- public int FirstID { get; set; }
-
- ///
- /// The ID of the second item of this link
- /// The second item of the link should be the owned resource.
- ///
- public int SecondID { get; set; }
-
- ///
- /// Create a new typeless .
- ///
- public Link() {}
-
- ///
- /// Create a new typeless with two IDs.
- ///
- /// The ID of the first resource
- /// The ID of the second resource
- public Link(int firstID, int secondID)
- {
- FirstID = firstID;
- SecondID = secondID;
- }
-
- ///
- /// Create a new typeless between two resources.
- ///
- /// The first resource
- /// The second resource
- public Link(IResource first, IResource second)
- {
- FirstID = first.ID;
- SecondID = second.ID;
- }
-
- ///
- /// Create a new typed link between two resources.
- /// This method can be used instead of the constructor to make use of generic parameters deduction.
- ///
- /// The first resource
- /// The second resource
- /// The type of the first resource
- /// The type of the second resource
- /// A newly created typed link with both resources
- public static Link Create(T first, T2 second)
- where T : class, IResource
- where T2 : class, IResource
- {
- return new(first, second);
- }
-
- ///
- /// Create a new typed link between two resources without storing references to resources.
- /// This is the same as but this method does not set
- /// and fields. Only IDs are stored and not references.
- ///
- /// The first resource
- /// The second resource
- /// The type of the first resource
- /// The type of the second resource
- /// A newly created typed link with both resources
- public static Link UCreate(T first, T2 second)
- where T : class, IResource
- where T2 : class, IResource
- {
- return new(first, second, true);
- }
-
- ///
- /// The expression to retrieve the unique ID of a Link. This is an aggregate of the two resources IDs.
- ///
- public static Expression> PrimaryKey
- {
- get
- {
- return x => new {First = x.FirstID, Second = x.SecondID};
- }
- }
- }
-
- ///
- /// A strongly typed link between two resources.
- ///
- /// The type of the first resource
- /// The type of the second resource
- public class Link : Link
- where T1 : class, IResource
- where T2 : class, IResource
- {
- ///
- /// A reference of the first resource.
- ///
- [SerializeIgnore] public T1 First { get; set; }
-
- ///
- /// A reference to the second resource.
- ///
- [SerializeIgnore] public T2 Second { get; set; }
-
-
- ///
- /// Create a new, empty, typed .
- ///
- public Link() {}
-
-
- ///
- /// Create a new typed link with two resources.
- ///
- /// The first resource
- /// The second resource
- ///
- /// True if no reference to resources should be kept, false otherwise.
- /// The default is false (references are kept).
- ///
- public Link(T1 first, T2 second, bool privateItems = false)
- : base(first, second)
- {
- if (privateItems)
- return;
- First = first;
- Second = second;
- }
-
- ///
- /// Create a new typed link with IDs only.
- ///
- /// The ID of the first resource
- /// The ID of the second resource
- public Link(int firstID, int secondID)
- : base(firstID, secondID)
- { }
-
- ///
- /// The expression to retrieve the unique ID of a typed Link. This is an aggregate of the two resources IDs.
- ///
- public new static Expression, object>> PrimaryKey
- {
- get
- {
- return x => new {First = x.FirstID, Second = x.SecondID};
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Kyoo.CommonAPI/DatabaseContext.cs b/Kyoo.CommonAPI/DatabaseContext.cs
index d2eb8e2f..fd850d02 100644
--- a/Kyoo.CommonAPI/DatabaseContext.cs
+++ b/Kyoo.CommonAPI/DatabaseContext.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
@@ -96,17 +97,23 @@ namespace Kyoo
}
///
- /// Get a generic link between two resource types.
+ /// Add a many to many link between two resources.
///
/// Types are order dependant. You can't inverse the order. Please always put the owner first.
+ /// The ID of the first resource.
+ /// The ID of the second resource.
/// The first resource type of the relation. It is the owner of the second
/// The second resource type of the relation. It is the contained resource.
- /// All links between the two types.
- public DbSet> Links()
+ public async Task AddLinks(int first, int second)
where T1 : class, IResource
where T2 : class, IResource
{
- return Set>();
+ await Set>(LinkName())
+ .AddAsync(new Dictionary
+ {
+ [LinkNameFk()] = first,
+ [LinkNameFk()] = second
+ });
}
@@ -141,6 +148,14 @@ namespace Kyoo
where T : IResource
where T2 : IResource;
+ ///
+ /// Get the name of a link's foreign key.
+ ///
+ /// The type that will be accessible via the navigation
+ /// The name of the foreign key for the given resource.
+ protected abstract string LinkNameFk()
+ where T : IResource;
+
///
/// Set basic configurations (like preventing query tracking)
///
@@ -168,6 +183,39 @@ namespace Kyoo
.HasForeignKey(x => x.ResourceID)
.OnDelete(DeleteBehavior.Cascade);
}
+
+ ///
+ /// Create a many to many relationship between the two entities.
+ /// The resulting relationship will have an available method.
+ ///
+ /// The database model builder
+ /// The first navigation expression from T to T2
+ /// The second navigation expression from T2 to T
+ /// The owning type of the relationship
+ /// The owned type of the relationship
+ private void _HasManyToMany(ModelBuilder modelBuilder,
+ Expression>> firstNavigation,
+ Expression>> secondNavigation)
+ where T : class, IResource
+ where T2 : class, IResource
+ {
+ modelBuilder.Entity()
+ .HasMany(secondNavigation)
+ .WithMany(firstNavigation)
+ .UsingEntity>(
+ LinkName(),
+ x => x
+ .HasOne()
+ .WithMany()
+ .HasForeignKey(LinkNameFk())
+ .OnDelete(DeleteBehavior.Cascade),
+ x => x
+ .HasOne()
+ .WithMany()
+ .HasForeignKey(LinkNameFk())
+ .OnDelete(DeleteBehavior.Cascade)
+ );
+ }
///
@@ -203,26 +251,12 @@ namespace Kyoo
.WithMany(x => x.Shows)
.OnDelete(DeleteBehavior.SetNull);
- modelBuilder.Entity()
- .HasMany(x => x.Libraries)
- .WithMany(x => x.Providers)
- .UsingEntity(x => x.ToTable(LinkName()));
- modelBuilder.Entity()
- .HasMany(x => x.Libraries)
- .WithMany(x => x.Collections)
- .UsingEntity(x => x.ToTable(LinkName()));
- modelBuilder.Entity()
- .HasMany(x => x.Libraries)
- .WithMany(x => x.Shows)
- .UsingEntity(x => x.ToTable(LinkName()));
- modelBuilder.Entity()
- .HasMany(x => x.Collections)
- .WithMany(x => x.Shows)
- .UsingEntity(x => x.ToTable(LinkName()));
- modelBuilder.Entity()
- .HasMany(x => x.Shows)
- .WithMany(x => x.Genres)
- .UsingEntity(x => x.ToTable(LinkName()));
+ _HasManyToMany(modelBuilder, x => x.Providers, x => x.Libraries);
+ _HasManyToMany(modelBuilder, x => x.Collections, x => x.Libraries);
+ _HasManyToMany(modelBuilder, x => x.Shows, x => x.Libraries);
+ _HasManyToMany(modelBuilder, x => x.Shows, x => x.Collections);
+ _HasManyToMany(modelBuilder, x => x.Genres, x => x.Shows);
+
modelBuilder.Entity()
.HasMany(x => x.Watched)
.WithMany("Users")
diff --git a/Kyoo.Postgresql/Migrations/20210730183548_Initial.Designer.cs b/Kyoo.Postgresql/Migrations/20210801171613_Initial.Designer.cs
similarity index 93%
rename from Kyoo.Postgresql/Migrations/20210730183548_Initial.Designer.cs
rename to Kyoo.Postgresql/Migrations/20210801171613_Initial.Designer.cs
index 10c42bb3..20b6f7bd 100644
--- a/Kyoo.Postgresql/Migrations/20210730183548_Initial.Designer.cs
+++ b/Kyoo.Postgresql/Migrations/20210801171613_Initial.Designer.cs
@@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations
{
[DbContext(typeof(PostgresContext))]
- [Migration("20210730183548_Initial")]
+ [Migration("20210801171613_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -26,63 +26,6 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "5.0.8")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
- modelBuilder.Entity("CollectionLibrary", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("integer")
- .HasColumnName("collections_id");
-
- b.Property("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("CollectionsID")
- .HasColumnType("integer")
- .HasColumnName("collections_id");
-
- b.Property("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("GenresID")
- .HasColumnType("integer")
- .HasColumnName("genres_id");
-
- b.Property("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 =>
{
b.Property("ID")
@@ -674,44 +617,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("watched_episodes");
});
- modelBuilder.Entity("LibraryProvider", b =>
- {
- b.Property("LibrariesID")
- .HasColumnType("integer")
- .HasColumnName("libraries_id");
-
- b.Property("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("LibrariesID")
- .HasColumnType("integer")
- .HasColumnName("libraries_id");
-
- b.Property("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 =>
{
b.Property("UsersID")
@@ -785,6 +690,101 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_metadata_id");
});
+ modelBuilder.Entity("link_collection_show", b =>
+ {
+ b.Property("collection_id")
+ .HasColumnType("integer")
+ .HasColumnName("collection_id");
+
+ b.Property("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("collection_id")
+ .HasColumnType("integer")
+ .HasColumnName("collection_id");
+
+ b.Property("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("library_id")
+ .HasColumnType("integer")
+ .HasColumnName("library_id");
+
+ b.Property("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("library_id")
+ .HasColumnType("integer")
+ .HasColumnName("library_id");
+
+ b.Property("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("genre_id")
+ .HasColumnType("integer")
+ .HasColumnName("genre_id");
+
+ b.Property("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 =>
{
b.Property("ResourceID")
@@ -893,57 +893,6 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Season", "Season")
@@ -1039,40 +988,6 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.User", null)
@@ -1128,6 +1043,91 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
diff --git a/Kyoo.Postgresql/Migrations/20210730183548_Initial.cs b/Kyoo.Postgresql/Migrations/20210801171613_Initial.cs
similarity index 93%
rename from Kyoo.Postgresql/Migrations/20210730183548_Initial.cs
rename to Kyoo.Postgresql/Migrations/20210801171613_Initial.cs
index dc37cba9..395d9e27 100644
--- a/Kyoo.Postgresql/Migrations/20210730183548_Initial.cs
+++ b/Kyoo.Postgresql/Migrations/20210801171613_Initial.cs
@@ -127,21 +127,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_library_collection",
columns: table => new
{
- collections_id = table.Column(type: "integer", nullable: false),
- libraries_id = table.Column(type: "integer", nullable: false)
+ collection_id = table.Column(type: "integer", nullable: false),
+ library_id = table.Column(type: "integer", nullable: false)
},
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(
- name: "fk_link_library_collection_collections_collections_id",
- column: x => x.collections_id,
+ name: "fk_link_library_collection_collections_collection_id",
+ column: x => x.collection_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "fk_link_library_collection_libraries_libraries_id",
- column: x => x.libraries_id,
+ name: "fk_link_library_collection_libraries_library_id",
+ column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
@@ -177,21 +177,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_library_provider",
columns: table => new
{
- libraries_id = table.Column(type: "integer", nullable: false),
- providers_id = table.Column(type: "integer", nullable: false)
+ library_id = table.Column(type: "integer", nullable: false),
+ provider_id = table.Column(type: "integer", nullable: false)
},
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(
- name: "fk_link_library_provider_libraries_libraries_id",
- column: x => x.libraries_id,
+ name: "fk_link_library_provider_libraries_library_id",
+ column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "fk_link_library_provider_providers_providers_id",
- column: x => x.providers_id,
+ name: "fk_link_library_provider_providers_provider_id",
+ column: x => x.provider_id,
principalTable: "providers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
@@ -282,21 +282,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_collection_show",
columns: table => new
{
- collections_id = table.Column(type: "integer", nullable: false),
- shows_id = table.Column(type: "integer", nullable: false)
+ collection_id = table.Column(type: "integer", nullable: false),
+ show_id = table.Column(type: "integer", nullable: false)
},
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(
- name: "fk_link_collection_show_collections_collections_id",
- column: x => x.collections_id,
+ name: "fk_link_collection_show_collections_collection_id",
+ column: x => x.collection_id,
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "fk_link_collection_show_shows_shows_id",
- column: x => x.shows_id,
+ name: "fk_link_collection_show_shows_show_id",
+ column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
@@ -306,21 +306,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_library_show",
columns: table => new
{
- libraries_id = table.Column(type: "integer", nullable: false),
- shows_id = table.Column(type: "integer", nullable: false)
+ library_id = table.Column(type: "integer", nullable: false),
+ show_id = table.Column(type: "integer", nullable: false)
},
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(
- name: "fk_link_library_show_libraries_libraries_id",
- column: x => x.libraries_id,
+ name: "fk_link_library_show_libraries_library_id",
+ column: x => x.library_id,
principalTable: "libraries",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "fk_link_library_show_shows_shows_id",
- column: x => x.shows_id,
+ name: "fk_link_library_show_shows_show_id",
+ column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
@@ -330,21 +330,21 @@ namespace Kyoo.Postgresql.Migrations
name: "link_show_genre",
columns: table => new
{
- genres_id = table.Column(type: "integer", nullable: false),
- shows_id = table.Column(type: "integer", nullable: false)
+ genre_id = table.Column(type: "integer", nullable: false),
+ show_id = table.Column(type: "integer", nullable: false)
},
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(
- name: "fk_link_show_genre_genres_genres_id",
- column: x => x.genres_id,
+ name: "fk_link_show_genre_genres_genre_id",
+ column: x => x.genre_id,
principalTable: "genres",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "fk_link_show_genre_shows_shows_id",
- column: x => x.shows_id,
+ name: "fk_link_show_genre_shows_show_id",
+ column: x => x.show_id,
principalTable: "shows",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
@@ -641,29 +641,29 @@ namespace Kyoo.Postgresql.Migrations
unique: true);
migrationBuilder.CreateIndex(
- name: "ix_link_collection_show_shows_id",
+ name: "ix_link_collection_show_show_id",
table: "link_collection_show",
- column: "shows_id");
+ column: "show_id");
migrationBuilder.CreateIndex(
- name: "ix_link_library_collection_libraries_id",
+ name: "ix_link_library_collection_library_id",
table: "link_library_collection",
- column: "libraries_id");
+ column: "library_id");
migrationBuilder.CreateIndex(
- name: "ix_link_library_provider_providers_id",
+ name: "ix_link_library_provider_provider_id",
table: "link_library_provider",
- column: "providers_id");
+ column: "provider_id");
migrationBuilder.CreateIndex(
- name: "ix_link_library_show_shows_id",
+ name: "ix_link_library_show_show_id",
table: "link_library_show",
- column: "shows_id");
+ column: "show_id");
migrationBuilder.CreateIndex(
- name: "ix_link_show_genre_shows_id",
+ name: "ix_link_show_genre_show_id",
table: "link_show_genre",
- column: "shows_id");
+ column: "show_id");
migrationBuilder.CreateIndex(
name: "ix_link_user_show_watched_id",
diff --git a/Kyoo.Postgresql/Migrations/20210730203102_Triggers.Designer.cs b/Kyoo.Postgresql/Migrations/20210801171641_Triggers.Designer.cs
similarity index 93%
rename from Kyoo.Postgresql/Migrations/20210730203102_Triggers.Designer.cs
rename to Kyoo.Postgresql/Migrations/20210801171641_Triggers.Designer.cs
index ff1ae33b..fd13824a 100644
--- a/Kyoo.Postgresql/Migrations/20210730203102_Triggers.Designer.cs
+++ b/Kyoo.Postgresql/Migrations/20210801171641_Triggers.Designer.cs
@@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations
{
[DbContext(typeof(PostgresContext))]
- [Migration("20210730203102_Triggers")]
+ [Migration("20210801171641_Triggers")]
partial class Triggers
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -26,63 +26,6 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "5.0.8")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
- modelBuilder.Entity("CollectionLibrary", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("integer")
- .HasColumnName("collections_id");
-
- b.Property("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("CollectionsID")
- .HasColumnType("integer")
- .HasColumnName("collections_id");
-
- b.Property("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("GenresID")
- .HasColumnType("integer")
- .HasColumnName("genres_id");
-
- b.Property("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 =>
{
b.Property("ID")
@@ -674,44 +617,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("watched_episodes");
});
- modelBuilder.Entity("LibraryProvider", b =>
- {
- b.Property("LibrariesID")
- .HasColumnType("integer")
- .HasColumnName("libraries_id");
-
- b.Property("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("LibrariesID")
- .HasColumnType("integer")
- .HasColumnName("libraries_id");
-
- b.Property("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 =>
{
b.Property("UsersID")
@@ -785,6 +690,101 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_metadata_id");
});
+ modelBuilder.Entity("link_collection_show", b =>
+ {
+ b.Property("collection_id")
+ .HasColumnType("integer")
+ .HasColumnName("collection_id");
+
+ b.Property("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("collection_id")
+ .HasColumnType("integer")
+ .HasColumnName("collection_id");
+
+ b.Property("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("library_id")
+ .HasColumnType("integer")
+ .HasColumnName("library_id");
+
+ b.Property("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("library_id")
+ .HasColumnType("integer")
+ .HasColumnName("library_id");
+
+ b.Property("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("genre_id")
+ .HasColumnType("integer")
+ .HasColumnName("genre_id");
+
+ b.Property("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 =>
{
b.Property("ResourceID")
@@ -893,57 +893,6 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Season", "Season")
@@ -1039,40 +988,6 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.User", null)
@@ -1128,6 +1043,91 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
diff --git a/Kyoo.Postgresql/Migrations/20210730203102_Triggers.cs b/Kyoo.Postgresql/Migrations/20210801171641_Triggers.cs
similarity index 98%
rename from Kyoo.Postgresql/Migrations/20210730203102_Triggers.cs
rename to Kyoo.Postgresql/Migrations/20210801171641_Triggers.cs
index f84b767b..6ee2961c 100644
--- a/Kyoo.Postgresql/Migrations/20210730203102_Triggers.cs
+++ b/Kyoo.Postgresql/Migrations/20210801171641_Triggers.cs
@@ -149,8 +149,8 @@ namespace Kyoo.Postgresql.Migrations
WHERE NOT (EXISTS (
SELECT 1
FROM link_collection_show AS l
- INNER JOIN collections AS c ON l.collections_id = c.id
- WHERE s.id = l.shows_id))
+ INNER JOIN collections AS c ON l.collection_id = c.id
+ WHERE s.id = l.show_id))
UNION ALL
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
diff --git a/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs b/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs
index 379b8d09..cd338b2f 100644
--- a/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs
+++ b/Kyoo.Postgresql/Migrations/PostgresContextModelSnapshot.cs
@@ -24,63 +24,6 @@ namespace Kyoo.Postgresql.Migrations
.HasAnnotation("ProductVersion", "5.0.8")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
- modelBuilder.Entity("CollectionLibrary", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("integer")
- .HasColumnName("collections_id");
-
- b.Property("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("CollectionsID")
- .HasColumnType("integer")
- .HasColumnName("collections_id");
-
- b.Property("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("GenresID")
- .HasColumnType("integer")
- .HasColumnName("genres_id");
-
- b.Property("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 =>
{
b.Property("ID")
@@ -672,44 +615,6 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("watched_episodes");
});
- modelBuilder.Entity("LibraryProvider", b =>
- {
- b.Property("LibrariesID")
- .HasColumnType("integer")
- .HasColumnName("libraries_id");
-
- b.Property("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("LibrariesID")
- .HasColumnType("integer")
- .HasColumnName("libraries_id");
-
- b.Property("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 =>
{
b.Property("UsersID")
@@ -783,6 +688,101 @@ namespace Kyoo.Postgresql.Migrations
b.ToTable("episode_metadata_id");
});
+ modelBuilder.Entity("link_collection_show", b =>
+ {
+ b.Property("collection_id")
+ .HasColumnType("integer")
+ .HasColumnName("collection_id");
+
+ b.Property("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("collection_id")
+ .HasColumnType("integer")
+ .HasColumnName("collection_id");
+
+ b.Property("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("library_id")
+ .HasColumnType("integer")
+ .HasColumnName("library_id");
+
+ b.Property("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("library_id")
+ .HasColumnType("integer")
+ .HasColumnName("library_id");
+
+ b.Property("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("genre_id")
+ .HasColumnType("integer")
+ .HasColumnName("genre_id");
+
+ b.Property("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 =>
{
b.Property("ResourceID")
@@ -891,57 +891,6 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Season", "Season")
@@ -1037,40 +986,6 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.User", null)
@@ -1126,6 +1041,91 @@ namespace Kyoo.Postgresql.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
diff --git a/Kyoo.Postgresql/PostgresContext.cs b/Kyoo.Postgresql/PostgresContext.cs
index eaea9927..36f12a8c 100644
--- a/Kyoo.Postgresql/PostgresContext.cs
+++ b/Kyoo.Postgresql/PostgresContext.cs
@@ -142,6 +142,13 @@ namespace Kyoo.Postgresql
SnakeCaseNameRewriter rewriter = new(CultureInfo.InvariantCulture);
return rewriter.RewriteName("Link" + typeof(T).Name + typeof(T2).Name);
}
+
+ ///
+ protected override string LinkNameFk()
+ {
+ SnakeCaseNameRewriter rewriter = new(CultureInfo.InvariantCulture);
+ return rewriter.RewriteName(typeof(T).Name + "ID");
+ }
///
protected override bool IsDuplicateException(Exception ex)
diff --git a/Kyoo.SqLite/Migrations/20210730203155_Initial.Designer.cs b/Kyoo.SqLite/Migrations/20210801171534_Initial.Designer.cs
similarity index 93%
rename from Kyoo.SqLite/Migrations/20210730203155_Initial.Designer.cs
rename to Kyoo.SqLite/Migrations/20210801171534_Initial.Designer.cs
index 48b89a25..0443a20d 100644
--- a/Kyoo.SqLite/Migrations/20210730203155_Initial.Designer.cs
+++ b/Kyoo.SqLite/Migrations/20210801171534_Initial.Designer.cs
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.SqLite.Migrations
{
[DbContext(typeof(SqLiteContext))]
- [Migration("20210730203155_Initial")]
+ [Migration("20210801171534_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -18,21 +18,6 @@ namespace Kyoo.SqLite.Migrations
modelBuilder
.HasAnnotation("ProductVersion", "5.0.8");
- modelBuilder.Entity("CollectionLibrary", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("INTEGER");
-
- b.Property("LibrariesID")
- .HasColumnType("INTEGER");
-
- b.HasKey("CollectionsID", "LibrariesID");
-
- b.HasIndex("LibrariesID");
-
- b.ToTable("LinkLibraryCollection");
- });
-
modelBuilder.Entity("CollectionMetadataID", b =>
{
b.Property("ResourceID")
@@ -54,21 +39,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("CollectionMetadataID");
});
- modelBuilder.Entity("CollectionShow", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("INTEGER");
-
- b.Property("ShowsID")
- .HasColumnType("INTEGER");
-
- b.HasKey("CollectionsID", "ShowsID");
-
- b.HasIndex("ShowsID");
-
- b.ToTable("LinkCollectionShow");
- });
-
modelBuilder.Entity("EpisodeMetadataID", b =>
{
b.Property("ResourceID")
@@ -90,21 +60,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("EpisodeMetadataID");
});
- modelBuilder.Entity("GenreShow", b =>
- {
- b.Property("GenresID")
- .HasColumnType("INTEGER");
-
- b.Property("ShowsID")
- .HasColumnType("INTEGER");
-
- b.HasKey("GenresID", "ShowsID");
-
- b.HasIndex("ShowsID");
-
- b.ToTable("LinkShowGenre");
- });
-
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property("ID")
@@ -558,36 +513,81 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("WatchedEpisodes");
});
- modelBuilder.Entity("LibraryProvider", b =>
+ modelBuilder.Entity("LinkCollectionShow", b =>
{
- b.Property("LibrariesID")
+ b.Property("CollectionID")
.HasColumnType("INTEGER");
- b.Property("ProvidersID")
+ b.Property("ShowID")
.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("CollectionID")
+ .HasColumnType("INTEGER");
+
+ b.Property("LibraryID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("CollectionID", "LibraryID");
+
+ b.HasIndex("LibraryID");
+
+ b.ToTable("LinkLibraryCollection");
+ });
+
+ modelBuilder.Entity("LinkLibraryProvider", b =>
+ {
+ b.Property("LibraryID")
+ .HasColumnType("INTEGER");
+
+ b.Property("ProviderID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("LibraryID", "ProviderID");
+
+ b.HasIndex("ProviderID");
b.ToTable("LinkLibraryProvider");
});
- modelBuilder.Entity("LibraryShow", b =>
+ modelBuilder.Entity("LinkLibraryShow", b =>
{
- b.Property("LibrariesID")
+ b.Property("LibraryID")
.HasColumnType("INTEGER");
- b.Property("ShowsID")
+ b.Property("ShowID")
.HasColumnType("INTEGER");
- b.HasKey("LibrariesID", "ShowsID");
+ b.HasKey("LibraryID", "ShowID");
- b.HasIndex("ShowsID");
+ b.HasIndex("ShowID");
b.ToTable("LinkLibraryShow");
});
+ modelBuilder.Entity("LinkShowGenre", b =>
+ {
+ b.Property("GenreID")
+ .HasColumnType("INTEGER");
+
+ b.Property("ShowID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("GenreID", "ShowID");
+
+ b.HasIndex("ShowID");
+
+ b.ToTable("LinkShowGenre");
+ });
+
modelBuilder.Entity("PeopleMetadataID", b =>
{
b.Property("ResourceID")
@@ -687,21 +687,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
@@ -719,21 +704,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
@@ -751,21 +721,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Season", "Season")
@@ -852,32 +807,77 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Episode");
});
- modelBuilder.Entity("LibraryProvider", b =>
+ modelBuilder.Entity("LinkCollectionShow", b =>
{
- b.HasOne("Kyoo.Models.Library", null)
+ b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
- .HasForeignKey("LibrariesID")
- .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")
+ .HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.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)
.IsRequired();
});
diff --git a/Kyoo.SqLite/Migrations/20210730203155_Initial.cs b/Kyoo.SqLite/Migrations/20210801171534_Initial.cs
similarity index 93%
rename from Kyoo.SqLite/Migrations/20210730203155_Initial.cs
rename to Kyoo.SqLite/Migrations/20210801171534_Initial.cs
index 82ae1dca..a7e62b03 100644
--- a/Kyoo.SqLite/Migrations/20210730203155_Initial.cs
+++ b/Kyoo.SqLite/Migrations/20210801171534_Initial.cs
@@ -119,21 +119,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkLibraryCollection",
columns: table => new
{
- CollectionsID = table.Column(type: "INTEGER", nullable: false),
- LibrariesID = table.Column(type: "INTEGER", nullable: false)
+ CollectionID = table.Column(type: "INTEGER", nullable: false),
+ LibraryID = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_LinkLibraryCollection", x => new { x.CollectionsID, x.LibrariesID });
+ table.PrimaryKey("PK_LinkLibraryCollection", x => new { x.CollectionID, x.LibraryID });
table.ForeignKey(
- name: "FK_LinkLibraryCollection_Collections_CollectionsID",
- column: x => x.CollectionsID,
+ name: "FK_LinkLibraryCollection_Collections_CollectionID",
+ column: x => x.CollectionID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_LinkLibraryCollection_Libraries_LibrariesID",
- column: x => x.LibrariesID,
+ name: "FK_LinkLibraryCollection_Libraries_LibraryID",
+ column: x => x.LibraryID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
@@ -169,21 +169,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkLibraryProvider",
columns: table => new
{
- LibrariesID = table.Column(type: "INTEGER", nullable: false),
- ProvidersID = table.Column(type: "INTEGER", nullable: false)
+ LibraryID = table.Column(type: "INTEGER", nullable: false),
+ ProviderID = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_LinkLibraryProvider", x => new { x.LibrariesID, x.ProvidersID });
+ table.PrimaryKey("PK_LinkLibraryProvider", x => new { x.LibraryID, x.ProviderID });
table.ForeignKey(
- name: "FK_LinkLibraryProvider_Libraries_LibrariesID",
- column: x => x.LibrariesID,
+ name: "FK_LinkLibraryProvider_Libraries_LibraryID",
+ column: x => x.LibraryID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_LinkLibraryProvider_Providers_ProvidersID",
- column: x => x.ProvidersID,
+ name: "FK_LinkLibraryProvider_Providers_ProviderID",
+ column: x => x.ProviderID,
principalTable: "Providers",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
@@ -274,21 +274,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkCollectionShow",
columns: table => new
{
- CollectionsID = table.Column(type: "INTEGER", nullable: false),
- ShowsID = table.Column(type: "INTEGER", nullable: false)
+ CollectionID = table.Column(type: "INTEGER", nullable: false),
+ ShowID = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_LinkCollectionShow", x => new { x.CollectionsID, x.ShowsID });
+ table.PrimaryKey("PK_LinkCollectionShow", x => new { x.CollectionID, x.ShowID });
table.ForeignKey(
- name: "FK_LinkCollectionShow_Collections_CollectionsID",
- column: x => x.CollectionsID,
+ name: "FK_LinkCollectionShow_Collections_CollectionID",
+ column: x => x.CollectionID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_LinkCollectionShow_Shows_ShowsID",
- column: x => x.ShowsID,
+ name: "FK_LinkCollectionShow_Shows_ShowID",
+ column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
@@ -298,21 +298,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkLibraryShow",
columns: table => new
{
- LibrariesID = table.Column(type: "INTEGER", nullable: false),
- ShowsID = table.Column(type: "INTEGER", nullable: false)
+ LibraryID = table.Column(type: "INTEGER", nullable: false),
+ ShowID = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_LinkLibraryShow", x => new { x.LibrariesID, x.ShowsID });
+ table.PrimaryKey("PK_LinkLibraryShow", x => new { x.LibraryID, x.ShowID });
table.ForeignKey(
- name: "FK_LinkLibraryShow_Libraries_LibrariesID",
- column: x => x.LibrariesID,
+ name: "FK_LinkLibraryShow_Libraries_LibraryID",
+ column: x => x.LibraryID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_LinkLibraryShow_Shows_ShowsID",
- column: x => x.ShowsID,
+ name: "FK_LinkLibraryShow_Shows_ShowID",
+ column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
@@ -322,21 +322,21 @@ namespace Kyoo.SqLite.Migrations
name: "LinkShowGenre",
columns: table => new
{
- GenresID = table.Column(type: "INTEGER", nullable: false),
- ShowsID = table.Column(type: "INTEGER", nullable: false)
+ GenreID = table.Column(type: "INTEGER", nullable: false),
+ ShowID = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_LinkShowGenre", x => new { x.GenresID, x.ShowsID });
+ table.PrimaryKey("PK_LinkShowGenre", x => new { x.GenreID, x.ShowID });
table.ForeignKey(
- name: "FK_LinkShowGenre_Genres_GenresID",
- column: x => x.GenresID,
+ name: "FK_LinkShowGenre_Genres_GenreID",
+ column: x => x.GenreID,
principalTable: "Genres",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_LinkShowGenre_Shows_ShowsID",
- column: x => x.ShowsID,
+ name: "FK_LinkShowGenre_Shows_ShowID",
+ column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
@@ -633,29 +633,29 @@ namespace Kyoo.SqLite.Migrations
unique: true);
migrationBuilder.CreateIndex(
- name: "IX_LinkCollectionShow_ShowsID",
+ name: "IX_LinkCollectionShow_ShowID",
table: "LinkCollectionShow",
- column: "ShowsID");
+ column: "ShowID");
migrationBuilder.CreateIndex(
- name: "IX_LinkLibraryCollection_LibrariesID",
+ name: "IX_LinkLibraryCollection_LibraryID",
table: "LinkLibraryCollection",
- column: "LibrariesID");
+ column: "LibraryID");
migrationBuilder.CreateIndex(
- name: "IX_LinkLibraryProvider_ProvidersID",
+ name: "IX_LinkLibraryProvider_ProviderID",
table: "LinkLibraryProvider",
- column: "ProvidersID");
+ column: "ProviderID");
migrationBuilder.CreateIndex(
- name: "IX_LinkLibraryShow_ShowsID",
+ name: "IX_LinkLibraryShow_ShowID",
table: "LinkLibraryShow",
- column: "ShowsID");
+ column: "ShowID");
migrationBuilder.CreateIndex(
- name: "IX_LinkShowGenre_ShowsID",
+ name: "IX_LinkShowGenre_ShowID",
table: "LinkShowGenre",
- column: "ShowsID");
+ column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_LinkUserShow_WatchedID",
diff --git a/Kyoo.SqLite/Migrations/20210730203746_Triggers.Designer.cs b/Kyoo.SqLite/Migrations/20210801171544_Triggers.Designer.cs
similarity index 93%
rename from Kyoo.SqLite/Migrations/20210730203746_Triggers.Designer.cs
rename to Kyoo.SqLite/Migrations/20210801171544_Triggers.Designer.cs
index fc59fcf6..05c1c174 100644
--- a/Kyoo.SqLite/Migrations/20210730203746_Triggers.Designer.cs
+++ b/Kyoo.SqLite/Migrations/20210801171544_Triggers.Designer.cs
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.SqLite.Migrations
{
[DbContext(typeof(SqLiteContext))]
- [Migration("20210730203746_Triggers")]
+ [Migration("20210801171544_Triggers")]
partial class Triggers
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -18,21 +18,6 @@ namespace Kyoo.SqLite.Migrations
modelBuilder
.HasAnnotation("ProductVersion", "5.0.8");
- modelBuilder.Entity("CollectionLibrary", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("INTEGER");
-
- b.Property("LibrariesID")
- .HasColumnType("INTEGER");
-
- b.HasKey("CollectionsID", "LibrariesID");
-
- b.HasIndex("LibrariesID");
-
- b.ToTable("LinkLibraryCollection");
- });
-
modelBuilder.Entity("CollectionMetadataID", b =>
{
b.Property("ResourceID")
@@ -54,21 +39,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("CollectionMetadataID");
});
- modelBuilder.Entity("CollectionShow", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("INTEGER");
-
- b.Property("ShowsID")
- .HasColumnType("INTEGER");
-
- b.HasKey("CollectionsID", "ShowsID");
-
- b.HasIndex("ShowsID");
-
- b.ToTable("LinkCollectionShow");
- });
-
modelBuilder.Entity("EpisodeMetadataID", b =>
{
b.Property("ResourceID")
@@ -90,21 +60,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("EpisodeMetadataID");
});
- modelBuilder.Entity("GenreShow", b =>
- {
- b.Property("GenresID")
- .HasColumnType("INTEGER");
-
- b.Property("ShowsID")
- .HasColumnType("INTEGER");
-
- b.HasKey("GenresID", "ShowsID");
-
- b.HasIndex("ShowsID");
-
- b.ToTable("LinkShowGenre");
- });
-
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property("ID")
@@ -558,36 +513,81 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("WatchedEpisodes");
});
- modelBuilder.Entity("LibraryProvider", b =>
+ modelBuilder.Entity("LinkCollectionShow", b =>
{
- b.Property("LibrariesID")
+ b.Property("CollectionID")
.HasColumnType("INTEGER");
- b.Property("ProvidersID")
+ b.Property("ShowID")
.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("CollectionID")
+ .HasColumnType("INTEGER");
+
+ b.Property("LibraryID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("CollectionID", "LibraryID");
+
+ b.HasIndex("LibraryID");
+
+ b.ToTable("LinkLibraryCollection");
+ });
+
+ modelBuilder.Entity("LinkLibraryProvider", b =>
+ {
+ b.Property("LibraryID")
+ .HasColumnType("INTEGER");
+
+ b.Property("ProviderID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("LibraryID", "ProviderID");
+
+ b.HasIndex("ProviderID");
b.ToTable("LinkLibraryProvider");
});
- modelBuilder.Entity("LibraryShow", b =>
+ modelBuilder.Entity("LinkLibraryShow", b =>
{
- b.Property("LibrariesID")
+ b.Property("LibraryID")
.HasColumnType("INTEGER");
- b.Property("ShowsID")
+ b.Property("ShowID")
.HasColumnType("INTEGER");
- b.HasKey("LibrariesID", "ShowsID");
+ b.HasKey("LibraryID", "ShowID");
- b.HasIndex("ShowsID");
+ b.HasIndex("ShowID");
b.ToTable("LinkLibraryShow");
});
+ modelBuilder.Entity("LinkShowGenre", b =>
+ {
+ b.Property("GenreID")
+ .HasColumnType("INTEGER");
+
+ b.Property("ShowID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("GenreID", "ShowID");
+
+ b.HasIndex("ShowID");
+
+ b.ToTable("LinkShowGenre");
+ });
+
modelBuilder.Entity("PeopleMetadataID", b =>
{
b.Property("ResourceID")
@@ -687,21 +687,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
@@ -719,21 +704,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
@@ -751,21 +721,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Season", "Season")
@@ -852,32 +807,77 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Episode");
});
- modelBuilder.Entity("LibraryProvider", b =>
+ modelBuilder.Entity("LinkCollectionShow", b =>
{
- b.HasOne("Kyoo.Models.Library", null)
+ b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
- .HasForeignKey("LibrariesID")
- .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")
+ .HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.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)
.IsRequired();
});
diff --git a/Kyoo.SqLite/Migrations/20210730203746_Triggers.cs b/Kyoo.SqLite/Migrations/20210801171544_Triggers.cs
similarity index 98%
rename from Kyoo.SqLite/Migrations/20210730203746_Triggers.cs
rename to Kyoo.SqLite/Migrations/20210801171544_Triggers.cs
index b3e3c5ae..789bc182 100644
--- a/Kyoo.SqLite/Migrations/20210730203746_Triggers.cs
+++ b/Kyoo.SqLite/Migrations/20210801171544_Triggers.cs
@@ -162,8 +162,8 @@ namespace Kyoo.SqLite.Migrations
WHERE NOT (EXISTS (
SELECT 1
FROM LinkCollectionShow AS l
- INNER JOIN Collections AS c ON l.CollectionsID = c.ID
- WHERE s.ID = l.ShowsID))
+ INNER JOIN Collections AS c ON l.CollectionID = c.ID
+ WHERE s.ID = l.ShowID))
UNION ALL
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
diff --git a/Kyoo.SqLite/Migrations/SqLiteContextModelSnapshot.cs b/Kyoo.SqLite/Migrations/SqLiteContextModelSnapshot.cs
index 28dc670c..50c96524 100644
--- a/Kyoo.SqLite/Migrations/SqLiteContextModelSnapshot.cs
+++ b/Kyoo.SqLite/Migrations/SqLiteContextModelSnapshot.cs
@@ -16,21 +16,6 @@ namespace Kyoo.SqLite.Migrations
modelBuilder
.HasAnnotation("ProductVersion", "5.0.8");
- modelBuilder.Entity("CollectionLibrary", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("INTEGER");
-
- b.Property("LibrariesID")
- .HasColumnType("INTEGER");
-
- b.HasKey("CollectionsID", "LibrariesID");
-
- b.HasIndex("LibrariesID");
-
- b.ToTable("LinkLibraryCollection");
- });
-
modelBuilder.Entity("CollectionMetadataID", b =>
{
b.Property("ResourceID")
@@ -52,21 +37,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("CollectionMetadataID");
});
- modelBuilder.Entity("CollectionShow", b =>
- {
- b.Property("CollectionsID")
- .HasColumnType("INTEGER");
-
- b.Property("ShowsID")
- .HasColumnType("INTEGER");
-
- b.HasKey("CollectionsID", "ShowsID");
-
- b.HasIndex("ShowsID");
-
- b.ToTable("LinkCollectionShow");
- });
-
modelBuilder.Entity("EpisodeMetadataID", b =>
{
b.Property("ResourceID")
@@ -88,21 +58,6 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("EpisodeMetadataID");
});
- modelBuilder.Entity("GenreShow", b =>
- {
- b.Property("GenresID")
- .HasColumnType("INTEGER");
-
- b.Property("ShowsID")
- .HasColumnType("INTEGER");
-
- b.HasKey("GenresID", "ShowsID");
-
- b.HasIndex("ShowsID");
-
- b.ToTable("LinkShowGenre");
- });
-
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property("ID")
@@ -556,36 +511,81 @@ namespace Kyoo.SqLite.Migrations
b.ToTable("WatchedEpisodes");
});
- modelBuilder.Entity("LibraryProvider", b =>
+ modelBuilder.Entity("LinkCollectionShow", b =>
{
- b.Property("LibrariesID")
+ b.Property("CollectionID")
.HasColumnType("INTEGER");
- b.Property("ProvidersID")
+ b.Property("ShowID")
.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("CollectionID")
+ .HasColumnType("INTEGER");
+
+ b.Property("LibraryID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("CollectionID", "LibraryID");
+
+ b.HasIndex("LibraryID");
+
+ b.ToTable("LinkLibraryCollection");
+ });
+
+ modelBuilder.Entity("LinkLibraryProvider", b =>
+ {
+ b.Property("LibraryID")
+ .HasColumnType("INTEGER");
+
+ b.Property("ProviderID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("LibraryID", "ProviderID");
+
+ b.HasIndex("ProviderID");
b.ToTable("LinkLibraryProvider");
});
- modelBuilder.Entity("LibraryShow", b =>
+ modelBuilder.Entity("LinkLibraryShow", b =>
{
- b.Property("LibrariesID")
+ b.Property("LibraryID")
.HasColumnType("INTEGER");
- b.Property("ShowsID")
+ b.Property("ShowID")
.HasColumnType("INTEGER");
- b.HasKey("LibrariesID", "ShowsID");
+ b.HasKey("LibraryID", "ShowID");
- b.HasIndex("ShowsID");
+ b.HasIndex("ShowID");
b.ToTable("LinkLibraryShow");
});
+ modelBuilder.Entity("LinkShowGenre", b =>
+ {
+ b.Property("GenreID")
+ .HasColumnType("INTEGER");
+
+ b.Property("ShowID")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("GenreID", "ShowID");
+
+ b.HasIndex("ShowID");
+
+ b.ToTable("LinkShowGenre");
+ });
+
modelBuilder.Entity("PeopleMetadataID", b =>
{
b.Property("ResourceID")
@@ -685,21 +685,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
@@ -717,21 +702,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Provider", "Provider")
@@ -749,21 +719,6 @@ namespace Kyoo.SqLite.Migrations
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 =>
{
b.HasOne("Kyoo.Models.Season", "Season")
@@ -850,32 +805,77 @@ namespace Kyoo.SqLite.Migrations
b.Navigation("Episode");
});
- modelBuilder.Entity("LibraryProvider", b =>
+ modelBuilder.Entity("LinkCollectionShow", b =>
{
- b.HasOne("Kyoo.Models.Library", null)
+ b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
- .HasForeignKey("LibrariesID")
- .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")
+ .HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.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)
.IsRequired();
});
diff --git a/Kyoo.SqLite/SqLiteContext.cs b/Kyoo.SqLite/SqLiteContext.cs
index e05d0308..cbd44659 100644
--- a/Kyoo.SqLite/SqLiteContext.cs
+++ b/Kyoo.SqLite/SqLiteContext.cs
@@ -155,6 +155,12 @@ namespace Kyoo.SqLite
{
return "Link" + typeof(T).Name + typeof(T2).Name;
}
+
+ ///
+ protected override string LinkNameFk()
+ {
+ return typeof(T).Name + "ID";
+ }
///
protected override bool IsDuplicateException(Exception ex)
diff --git a/Kyoo/Controllers/Repositories/EpisodeRepository.cs b/Kyoo/Controllers/Repositories/EpisodeRepository.cs
index ee5d2cdd..d50fe8c4 100644
--- a/Kyoo/Controllers/Repositories/EpisodeRepository.cs
+++ b/Kyoo/Controllers/Repositories/EpisodeRepository.cs
@@ -141,12 +141,16 @@ namespace Kyoo.Controllers
/// The parameter is returned.
private async Task 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.EpisodeSlug = resource.Slug;
return _tracks.Create(x);
- }).ToListAsync());
+ }).ToListAsync();
+ _database.Tracks.AttachRange(resource.Tracks);
return resource;
}
@@ -155,8 +159,12 @@ namespace Kyoo.Controllers
{
await base.Validate(resource);
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)
{
diff --git a/Kyoo/Controllers/Repositories/ShowRepository.cs b/Kyoo/Controllers/Repositories/ShowRepository.cs
index 458690f7..d74c2fe3 100644
--- a/Kyoo/Controllers/Repositories/ShowRepository.cs
+++ b/Kyoo/Controllers/Repositories/ShowRepository.cs
@@ -159,21 +159,18 @@ namespace Kyoo.Controllers
{
if (collectionID != null)
{
- await _database.Links()
- .AddAsync(new Link(collectionID.Value, showID));
+ await _database.AddLinks(collectionID.Value, showID);
await _database.SaveIfNoDuplicates();
if (libraryID != null)
{
- await _database.Links()
- .AddAsync(new Link(libraryID.Value, collectionID.Value));
+ await _database.AddLinks(libraryID.Value, collectionID.Value);
await _database.SaveIfNoDuplicates();
}
}
if (libraryID != null)
{
- await _database.Links()
- .AddAsync(new Link(libraryID.Value, showID));
+ await _database.AddLinks(libraryID.Value, showID);
await _database.SaveIfNoDuplicates();
}
}
diff --git a/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs b/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs
index d004f954..d3111f75 100644
--- a/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs
+++ b/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs
@@ -360,5 +360,18 @@ namespace Kyoo.Tests.Database
Assert.Equal(0, await Repositories.LibraryManager.SeasonRepository.GetCount());
Assert.Equal(0, await Repositories.LibraryManager.EpisodeRepository.GetCount());
}
+
+ [Fact]
+ public async Task AddShowLinkTest()
+ {
+ await Repositories.LibraryManager.Create(TestSample.GetNew());
+ 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));
+ }
}
}
\ No newline at end of file