Reworking the plugin interface and moving the database to an external dll

This commit is contained in:
Zoe Roux 2021-04-28 23:40:22 +02:00
parent b7294114b9
commit 833447ded8
21 changed files with 365 additions and 2360 deletions

View File

@ -1,8 +1,14 @@
using JetBrains.Annotations;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Unity;
namespace Kyoo.Controllers
{
/// <summary>
/// A common interface used to discord plugins
/// </summary>
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IPlugin
{
/// <summary>
@ -19,21 +25,35 @@ namespace Kyoo.Controllers
/// The description of this plugin. This will be displayed on the "installed plugins" page.
/// </summary>
string Description { get; }
/// <summary>
/// A configure method that will be runned on plugin's startup.
/// A list of services that are provided by this service. This allow other plugins to declare dependencies.
/// </summary>
/// <remarks>
/// You can have use any services as parameter, they will be injected from the service provider
/// You can add managed types or any type you like using the IUnityContainer like so:
/// <code>
/// public static void Configure(IUnityContainer services)
/// {
/// services.AddTask&lt;MyTask&gt;()
/// }
/// </code>
/// The format should be the name of the interface ':' and the name of the implementation.
/// For a plugins that provide a new service named IService with a default implementation named Koala, that would
/// be "IService:Koala".
/// </remarks>
static void Configure() { }
string[] Provides { get; }
/// <summary>
/// A list of services that are required by this service.
/// The Core will warn the user that this plugin can't be loaded if a required service is not found.
/// </summary>
/// <remarks>
/// This is the same format as <see cref="Provides"/> but you may leave a blank implementation's name if you don't need a special one.
/// For example, if you need a service named IService but you don't care what implementation it will be, you can use
/// "IService:"
/// </remarks>
string[] Requires { get; }
/// <summary>
/// A configure method that will be run on plugin's startup.
/// </summary>
/// <param name="container">A unity container to register new services.</param>
/// <param name="config">The configuration, if you need values at config time (database connection strings...)</param>
/// <param name="app">The Asp.Net application builder. On most case it is not needed but you can use it to add asp net functionalities.</param>
/// <param name="debugMode">True if the app should run in debug mode.</param>
void Configure(IUnityContainer container, IConfiguration config, IApplicationBuilder app, bool debugMode);
}
}

View File

@ -18,7 +18,7 @@ namespace Kyoo.Controllers
/// <param name="arguments">A list of arguments to pass to the task. An automatic conversion will be made if arguments to not fit.</param>
/// <exception cref="ArgumentException">If the number of arguments is invalid or if an argument can't be converted.</exception>
/// <exception cref="ItemNotFound">The task could not be found.</exception>
void StartTask(string taskSlug, Dictionary<string, object> arguments);
void StartTask(string taskSlug, Dictionary<string, object> arguments = null);
/// <summary>
/// Get all currently running tasks

View File

@ -23,6 +23,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" PrivateAssets="All" />
<PackageReference Include="Unity.Abstractions" Version="5.11.7" />
</ItemGroup>

View File

@ -1,3 +1,4 @@
using System;
using Kyoo.Controllers;
using Unity;
@ -11,14 +12,14 @@ namespace Kyoo
/// <summary>
/// Register a new task to the container.
/// </summary>
/// <param name="services">The container</param>
/// <param name="container">The container</param>
/// <typeparam name="T">The type of the task</typeparam>
/// <returns>The initial container.</returns>
public static IUnityContainer AddTask<T>(this IUnityContainer services)
public static IUnityContainer RegisterTask<T>(this IUnityContainer container)
where T : class, ITask
{
services.RegisterSingleton<ITask, T>();
return services;
container.RegisterType<ITask, T>();
return container;
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Kyoo/Kyoo.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,76 @@
using System;
using Kyoo.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Npgsql;
namespace Kyoo.Postgresql
{
/// <summary>
/// A postgresql implementation of <see cref="DatabaseContext"/>.
/// </summary>
public class PostgresContext : DatabaseContext
{
/// <summary>
/// The connection string to use.
/// </summary>
private readonly string _connection;
/// <summary>
/// Is this instance in debug mode?
/// </summary>
private readonly bool _debugMode;
/// <summary>
/// A basic constructor that set default values (query tracker behaviors, mapping enums...)
/// </summary>
public PostgresContext()
{
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
}
/// <summary>
/// A basic constructor that set default values (query tracker behaviors, mapping enums...)
/// </summary>
/// <param name="connection">The connection string to use</param>
/// <param name="debugMode">Is this instance in debug mode?</param>
public PostgresContext(string connection, bool debugMode)
{
_connection = connection;
_debugMode = debugMode;
}
/// <summary>
/// Set connection information for this database context
/// </summary>
/// <param name="optionsBuilder">An option builder to fill.</param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(_connection);
if (_debugMode)
optionsBuilder.EnableDetailedErrors()
.EnableSensitiveDataLogging();
}
/// <summary>
/// Set database parameters to support every types of Kyoo.
/// </summary>
/// <param name="modelBuilder">The database's model builder.</param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresEnum<Status>();
modelBuilder.HasPostgresEnum<ItemType>();
modelBuilder.HasPostgresEnum<StreamType>();
base.OnModelCreating(modelBuilder);
}
/// <inheritdoc />
protected override bool IsDuplicateException(Exception ex)
{
return ex.InnerException is PostgresException {SqlState: PostgresErrorCodes.UniqueViolation};
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using Kyoo.Controllers;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Unity;
using Unity.Injection;
using Unity.Lifetime;
using Unity.Resolution;
namespace Kyoo.Postgresql
{
/// <summary>
/// A module to add postgresql capacity to the app.
/// </summary>
public class PostgresModule : IPlugin
{
/// <inheritdoc />
public string Slug => "postgresql";
/// <inheritdoc />
public string Name => "Postgresql";
/// <inheritdoc />
public string Description => "A database context for postgresql.";
/// <inheritdoc />
public string[] Provides => new[]
{
$"{nameof(DatabaseContext)}:{nameof(PostgresContext)}"
};
/// <inheritdoc />
public string[] Requires => Array.Empty<string>();
/// <inheritdoc />
public void Configure(IUnityContainer container, IConfiguration config, IApplicationBuilder app, bool debugMode)
{
// options.UseNpgsql(_configuration.GetDatabaseConnection());
// // // .EnableSensitiveDataLogging()
// // // .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
container.RegisterFactory<DatabaseContext>(_ =>
{
return new PostgresContext(config.GetDatabaseConnection(), debugMode);
});
}
}
}

View File

@ -1,79 +1,79 @@
using Kyoo.Models;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace Kyoo.Tests
{
/// <summary>
/// Class responsible to fill and create in memory databases for unit tests.
/// </summary>
public class TestContext
{
/// <summary>
/// The context's options that specify to use an in memory Sqlite database.
/// </summary>
private readonly DbContextOptions<DatabaseContext> _context;
/// <summary>
/// Create a new database and fill it with informations.
/// </summary>
public TestContext()
{
SqliteConnection connection = new("DataSource=:memory:");
connection.Open();
try
{
_context = new DbContextOptionsBuilder<DatabaseContext>()
.UseSqlite(connection)
.Options;
FillDatabase();
}
finally
{
connection.Close();
}
}
/// <summary>
/// Fill the database with pre defined values using a clean context.
/// </summary>
private void FillDatabase()
{
using DatabaseContext context = new(_context);
context.Shows.Add(new Show
{
ID = 67,
Slug = "anohana",
Title = "Anohana: The Flower We Saw That Day",
Aliases = new[]
{
"Ano Hi Mita Hana no Namae o Bokutachi wa Mada Shiranai.",
"AnoHana",
"We Still Don't Know the Name of the Flower We Saw That Day."
},
Overview = "When Yadomi Jinta was a child, he was a central piece in a group of close friends. " +
"In time, however, these childhood friends drifted apart, and when they became high " +
"school students, they had long ceased to think of each other as friends.",
Status = Status.Finished,
TrailerUrl = null,
StartYear = 2011,
EndYear = 2011,
Poster = "poster",
Logo = "logo",
Backdrop = "backdrop",
IsMovie = false,
Studio = null
});
}
/// <summary>
/// Get a new databse context connected to a in memory Sqlite databse.
/// </summary>
/// <returns>A valid DatabaseContext</returns>
public DatabaseContext New()
{
return new(_context);
}
}
}
// using Kyoo.Models;
// using Microsoft.Data.Sqlite;
// using Microsoft.EntityFrameworkCore;
//
// namespace Kyoo.Tests
// {
// /// <summary>
// /// Class responsible to fill and create in memory databases for unit tests.
// /// </summary>
// public class TestContext
// {
// /// <summary>
// /// The context's options that specify to use an in memory Sqlite database.
// /// </summary>
// private readonly DbContextOptions<DatabaseContext> _context;
//
// /// <summary>
// /// Create a new database and fill it with information.
// /// </summary>
// public TestContext()
// {
// SqliteConnection connection = new("DataSource=:memory:");
// connection.Open();
//
// try
// {
// _context = new DbContextOptionsBuilder<DatabaseContext>()
// .UseSqlite(connection)
// .Options;
// FillDatabase();
// }
// finally
// {
// connection.Close();
// }
// }
//
// /// <summary>
// /// Fill the database with pre defined values using a clean context.
// /// </summary>
// private void FillDatabase()
// {
// using DatabaseContext context = new(_context);
// context.Shows.Add(new Show
// {
// ID = 67,
// Slug = "anohana",
// Title = "Anohana: The Flower We Saw That Day",
// Aliases = new[]
// {
// "Ano Hi Mita Hana no Namae o Bokutachi wa Mada Shiranai.",
// "AnoHana",
// "We Still Don't Know the Name of the Flower We Saw That Day."
// },
// Overview = "When Yadomi Jinta was a child, he was a central piece in a group of close friends. " +
// "In time, however, these childhood friends drifted apart, and when they became high " +
// "school students, they had long ceased to think of each other as friends.",
// Status = Status.Finished,
// TrailerUrl = null,
// StartYear = 2011,
// EndYear = 2011,
// Poster = "poster",
// Logo = "logo",
// Backdrop = "backdrop",
// IsMovie = false,
// Studio = null
// });
// }
//
// /// <summary>
// /// Get a new database context connected to a in memory Sqlite database.
// /// </summary>
// /// <returns>A valid DatabaseContext</returns>
// public DatabaseContext New()
// {
// return new(_context);
// }
// }
// }

View File

@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.CommonAPI", "Kyoo.Comm
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Tests", "Kyoo.Tests\Kyoo.Tests.csproj", "{D179D5FF-9F75-4B27-8E27-0DBDF1806611}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Postgresql", "Kyoo.Postgresql\Kyoo.Postgresql.csproj", "{3213C96D-0BF3-460B-A8B5-B9977229408A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -29,5 +31,9 @@ Global
{D179D5FF-9F75-4B27-8E27-0DBDF1806611}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D179D5FF-9F75-4B27-8E27-0DBDF1806611}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D179D5FF-9F75-4B27-8E27-0DBDF1806611}.Release|Any CPU.Build.0 = Release|Any CPU
{3213C96D-0BF3-460B-A8B5-B9977229408A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3213C96D-0BF3-460B-A8B5-B9977229408A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3213C96D-0BF3-460B-A8B5-B9977229408A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3213C96D-0BF3-460B-A8B5-B9977229408A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@ -20,10 +19,6 @@ namespace Kyoo.Controllers
/// </summary>
private readonly DatabaseContext _database;
/// <summary>
/// A provider repository to handle externalID creation and deletion
/// </summary>
private readonly IProviderRepository _providers;
/// <summary>
/// A lazy loaded library repository to validate queries (check if a library does exist)
/// </summary>
private readonly Lazy<ILibraryRepository> _libraries;
@ -44,18 +39,19 @@ namespace Kyoo.Controllers
/// Create a new <see cref="LibraryItemRepository"/>.
/// </summary>
/// <param name="database">The databse instance</param>
/// <param name="providers">A provider repository</param>
/// <param name="services">A service provider to lazilly request a library, show or collection repository.</param>
/// <param name="libraries">A lazy loaded library repository</param>
/// <param name="shows">A lazy loaded show repository</param>
/// <param name="collections">A lazy loaded collection repository</param>
public LibraryItemRepository(DatabaseContext database,
IProviderRepository providers,
IServiceProvider services)
Lazy<ILibraryRepository> libraries,
Lazy<IShowRepository> shows,
Lazy<ICollectionRepository> collections)
: base(database)
{
_database = database;
_providers = providers;
_libraries = new Lazy<ILibraryRepository>(services.GetRequiredService<ILibraryRepository>);
_shows = new Lazy<IShowRepository>(services.GetRequiredService<IShowRepository>);
_collections = new Lazy<ICollectionRepository>(services.GetRequiredService<ICollectionRepository>);
_libraries = libraries;
_shows = shows;
_collections = collections;
}

View File

@ -36,15 +36,15 @@ namespace Kyoo.Controllers
/// </summary>
/// <param name="database">The database handle</param>
/// <param name="providers">A provider repository</param>
/// <param name="services">A service provider to lazy load a show repository</param>
/// <param name="shows">A lazy loaded show repository</param>
public PeopleRepository(DatabaseContext database,
IProviderRepository providers,
IServiceProvider services)
Lazy<IShowRepository> shows)
: base(database)
{
_database = database;
_providers = providers;
_shows = new Lazy<IShowRepository>(services.GetRequiredService<IShowRepository>);
_shows = shows;
}

View File

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@ -44,17 +43,17 @@ namespace Kyoo.Controllers
/// <param name="database">The database handle that will be used</param>
/// <param name="providers">A provider repository</param>
/// <param name="shows">A show repository</param>
/// <param name="services">A service provider to lazilly request an episode repository.</param>
/// <param name="episodes">A lazy loaded episode repository.</param>
public SeasonRepository(DatabaseContext database,
IProviderRepository providers,
IShowRepository shows,
IServiceProvider services)
Lazy<IEpisodeRepository> episodes)
: base(database)
{
_database = database;
_providers = providers;
_shows = shows;
_episodes = new Lazy<IEpisodeRepository>(services.GetRequiredService<IEpisodeRepository>);
_episodes = episodes;
}

View File

@ -5,7 +5,6 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using Kyoo.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@ -54,13 +53,15 @@ namespace Kyoo.Controllers
/// <param name="people">A people repository</param>
/// <param name="genres">A genres repository</param>
/// <param name="providers">A provider repository</param>
/// <param name="services">A service provider to lazilly request a season and an episode repository</param>
/// <param name="seasons">A lazy loaded season repository</param>
/// <param name="episodes">A lazy loaded episode repository</param>
public ShowRepository(DatabaseContext database,
IStudioRepository studios,
IPeopleRepository people,
IGenreRepository genres,
IProviderRepository providers,
IServiceProvider services)
Lazy<ISeasonRepository> seasons,
Lazy<IEpisodeRepository> episodes)
: base(database)
{
_database = database;
@ -68,8 +69,8 @@ namespace Kyoo.Controllers
_people = people;
_genres = genres;
_providers = providers;
_seasons = new Lazy<ISeasonRepository>(services.GetRequiredService<ISeasonRepository>);
_episodes = new Lazy<IEpisodeRepository>(services.GetRequiredService<IEpisodeRepository>);
_seasons = seasons;
_episodes = episodes;
}

View File

@ -62,10 +62,10 @@ namespace Kyoo.Controllers
IConfiguration configuration,
ILogger<TaskManager> logger)
{
_tasks = tasks.Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
_container = container;
_configuration = configuration.GetSection("scheduledTasks");
_logger = logger;
_tasks = tasks.Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
}
@ -179,8 +179,10 @@ namespace Kyoo.Controllers
}
/// <inheritdoc />
public void StartTask(string taskSlug, Dictionary<string, object> arguments)
public void StartTask(string taskSlug, Dictionary<string, object> arguments = null)
{
arguments ??= new Dictionary<string, object>();
int index = _tasks.FindIndex(x => x.task.Slug == taskSlug);
if (index == -1)
throw new ItemNotFound($"No task found with the slug {taskSlug}");
@ -216,7 +218,7 @@ namespace Kyoo.Controllers
/// <inheritdoc />
public void ReloadTasks()
{
_tasks = _container.ResolveAll<ITask>().Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
_tasks = _container.Resolve<IEnumerable<ITask>>().Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
EnqueueStartupTasks();
}
}

View File

@ -1,10 +1,14 @@
using Kyoo.Controllers;
using Kyoo.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Unity;
using Unity.Lifetime;
namespace Kyoo
{
/// <summary>
/// The core module ccontaining default implementations
/// The core module containing default implementations
/// </summary>
public class CoreModule : IPlugin
{
@ -17,10 +21,60 @@ namespace Kyoo
/// <inheritdoc />
public string Description => "The core module containing default implementations.";
/// <inheritdoc cref="IPlugin.Configure" />
public static void Configure(IUnityContainer container)
/// <inheritdoc />
public string[] Provides => new[]
{
container.AddTask<Crawler>();
$"{nameof(IFileManager)}:file",
$"{nameof(ITranscoder)}:{nameof(Transcoder)}",
$"{nameof(IThumbnailsManager)}:{nameof(ThumbnailsManager)}",
$"{nameof(IProviderManager)}:{nameof(ProviderManager)}",
$"{nameof(IPluginManager)}:{nameof(PluginManager)}",
$"{nameof(ITaskManager)}:{nameof(TaskManager)}",
$"{nameof(ILibraryManager)}:{nameof(LibraryManager)}",
$"{nameof(ILibraryRepository)}:{nameof(LibraryRepository)}",
$"{nameof(ILibraryItemRepository)}:{nameof(LibraryItemRepository)}",
$"{nameof(ICollectionRepository)}:{nameof(CollectionRepository)}",
$"{nameof(IShowRepository)}:{nameof(ShowRepository)}",
$"{nameof(ISeasonRepository)}:{nameof(SeasonRepository)}",
$"{nameof(IEpisodeRepository)}:{nameof(EpisodeRepository)}",
$"{nameof(ITrackRepository)}:{nameof(TrackRepository)}",
$"{nameof(IPeopleRepository)}:{nameof(PeopleRepository)}",
$"{nameof(IStudioRepository)}:{nameof(StudioRepository)}",
$"{nameof(IGenreRepository)}:{nameof(GenreRepository)}",
$"{nameof(IProviderRepository)}:{nameof(ProviderRepository)}"
};
/// <inheritdoc />
public string[] Requires => new[]
{
"DatabaseContext:"
};
/// <inheritdoc />
public void Configure(IUnityContainer container, IConfiguration config, IApplicationBuilder app, bool debugMode)
{
container.RegisterType<IFileManager, FileManager>(new SingletonLifetimeManager());
container.RegisterType<ITranscoder, Transcoder>(new SingletonLifetimeManager());
container.RegisterType<IThumbnailsManager, ThumbnailsManager>(new SingletonLifetimeManager());
container.RegisterType<IProviderManager, ProviderManager>(new SingletonLifetimeManager());
container.RegisterType<IPluginManager, PluginManager>(new SingletonLifetimeManager());
container.RegisterType<ITaskManager, TaskManager>(new SingletonLifetimeManager());
container.RegisterType<ILibraryManager, LibraryManager>(new HierarchicalLifetimeManager());
container.RegisterType<ILibraryRepository, LibraryRepository>(new HierarchicalLifetimeManager());
container.RegisterType<ILibraryItemRepository, LibraryItemRepository>(new HierarchicalLifetimeManager());
container.RegisterType<ICollectionRepository, CollectionRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IShowRepository, ShowRepository>(new HierarchicalLifetimeManager());
container.RegisterType<ISeasonRepository, SeasonRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IEpisodeRepository, EpisodeRepository>(new HierarchicalLifetimeManager());
container.RegisterType<ITrackRepository, TrackRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IPeopleRepository, PeopleRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IStudioRepository, StudioRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IGenreRepository, GenreRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IProviderRepository, ProviderRepository>(new HierarchicalLifetimeManager());
container.RegisterTask<Crawler>();
}
}
}

View File

@ -7,17 +7,17 @@ using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Npgsql;
namespace Kyoo
{
/// <summary>
/// The database handle used for all local repositories.
/// This is an abstract class. It is meant to be implemented by plugins. This allow the core to be database agnostic.
/// </summary>
/// <remarks>
/// It should not be used directly, to access the database use a <see cref="ILibraryManager"/> or repositories.
/// </remarks>
public class DatabaseContext : DbContext
public abstract class DatabaseContext : DbContext
{
/// <summary>
/// All libraries of Kyoo. See <see cref="Library"/>.
@ -89,10 +89,6 @@ namespace Kyoo
/// </summary>
public DatabaseContext()
{
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemType>();
NpgsqlConnection.GlobalTypeMapper.MapEnum<StreamType>();
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
ChangeTracker.LazyLoadingEnabled = false;
}
@ -100,7 +96,7 @@ namespace Kyoo
/// <summary>
/// Create a new <see cref="DatabaseContext"/>.
/// </summary>
/// <param name="options">Connection options to use (witch databse provider to use, connection strings...)</param>
/// <param name="options">Connection options to use (witch database provider to use, connection strings...)</param>
public DatabaseContext(DbContextOptions<DatabaseContext> options)
: base(options)
{
@ -116,10 +112,6 @@ namespace Kyoo
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasPostgresEnum<Status>();
modelBuilder.HasPostgresEnum<ItemType>();
modelBuilder.HasPostgresEnum<StreamType>();
modelBuilder.Entity<Track>()
.Property(t => t.IsDefault)
.ValueGeneratedNever();
@ -467,13 +459,9 @@ namespace Kyoo
/// <summary>
/// Check if the exception is a duplicated exception.
/// </summary>
/// <remarks>WARNING: this only works for PostgreSQL</remarks>
/// <param name="ex">The exception to check</param>
/// <returns>True if the exception is a duplicate exception. False otherwise</returns>
private static bool IsDuplicateException(Exception ex)
{
return ex.InnerException is PostgresException {SqlState: PostgresErrorCodes.UniqueViolation};
}
protected abstract bool IsDuplicateException(Exception ex);
/// <summary>
/// Delete every changes that are on this context.

View File

@ -1,785 +0,0 @@
// <auto-generated />
using System;
using Kyoo;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
[DbContext(typeof(DatabaseContext))]
[Migration("20210420221509_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasPostgresEnum(null, "item_type", new[] { "show", "movie", "collection" })
.HasPostgresEnum(null, "status", new[] { "finished", "airing", "planned", "unknown" })
.HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" })
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Collections");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("AbsoluteNumber")
.HasColumnType("integer");
b.Property<int>("EpisodeNumber")
.HasColumnType("integer");
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Path")
.HasColumnType("text");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp without time zone");
b.Property<int>("Runtime")
.HasColumnType("integer");
b.Property<int?>("SeasonID")
.HasColumnType("integer");
b.Property<int>("SeasonNumber")
.HasColumnType("integer");
b.Property<int>("ShowID")
.HasColumnType("integer");
b.Property<string>("Thumb")
.HasColumnType("text");
b.Property<string>("Title")
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("SeasonID");
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
b.ToTable("Episodes");
});
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Genres");
});
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string[]>("Paths")
.HasColumnType("text[]");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Libraries");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Collection, Kyoo.Models.Show>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Collection, Show>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Collection>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Library, Collection>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Provider>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Library, Provider>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Show>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Library, Show>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Show, Kyoo.Models.Genre>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Show, Genre>");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("DataID")
.HasColumnType("text");
b.Property<int?>("EpisodeID")
.HasColumnType("integer");
b.Property<string>("Link")
.HasColumnType("text");
b.Property<int?>("PeopleID")
.HasColumnType("integer");
b.Property<int>("ProviderID")
.HasColumnType("integer");
b.Property<int?>("SeasonID")
.HasColumnType("integer");
b.Property<int?>("ShowID")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("EpisodeID");
b.HasIndex("PeopleID");
b.HasIndex("ProviderID");
b.HasIndex("SeasonID");
b.HasIndex("ShowID");
b.ToTable("MetadataIds");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("People");
});
modelBuilder.Entity("Kyoo.Models.PeopleRole", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("PeopleID")
.HasColumnType("integer");
b.Property<string>("Role")
.HasColumnType("text");
b.Property<int>("ShowID")
.HasColumnType("integer");
b.Property<string>("Type")
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("PeopleID");
b.HasIndex("ShowID");
b.ToTable("PeopleRoles");
});
modelBuilder.Entity("Kyoo.Models.Provider", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Logo")
.HasColumnType("text");
b.Property<string>("LogoExtension")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Providers");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<int>("SeasonNumber")
.HasColumnType("integer");
b.Property<int>("ShowID")
.HasColumnType("integer");
b.Property<string>("Title")
.HasColumnType("text");
b.Property<int?>("Year")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
b.ToTable("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string[]>("Aliases")
.HasColumnType("text[]");
b.Property<string>("Backdrop")
.HasColumnType("text");
b.Property<int?>("EndYear")
.HasColumnType("integer");
b.Property<bool>("IsMovie")
.HasColumnType("boolean");
b.Property<string>("Logo")
.HasColumnType("text");
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Path")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("StartYear")
.HasColumnType("integer");
b.Property<int?>("Status")
.HasColumnType("integer");
b.Property<int?>("StudioID")
.HasColumnType("integer");
b.Property<string>("Title")
.HasColumnType("text");
b.Property<string>("TrailerUrl")
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("StudioID");
b.ToTable("Shows");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Studios");
});
modelBuilder.Entity("Kyoo.Models.Track", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Codec")
.HasColumnType("text");
b.Property<int>("EpisodeID")
.HasColumnType("integer");
b.Property<bool>("IsDefault")
.HasColumnType("boolean");
b.Property<bool>("IsExternal")
.HasColumnType("boolean");
b.Property<bool>("IsForced")
.HasColumnType("boolean");
b.Property<string>("Language")
.HasColumnType("text");
b.Property<string>("Path")
.HasColumnType("text");
b.Property<string>("Title")
.HasColumnType("text");
b.Property<int>("TrackIndex")
.HasColumnType("integer");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();
b.ToTable("Tracks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.HasOne("Kyoo.Models.Season", "Season")
.WithMany("Episodes")
.HasForeignKey("SeasonID");
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Episodes")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Season");
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Collection, Kyoo.Models.Show>", b =>
{
b.HasOne("Kyoo.Models.Collection", "First")
.WithMany("ShowLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Second")
.WithMany("CollectionLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Collection>", b =>
{
b.HasOne("Kyoo.Models.Library", "First")
.WithMany("CollectionLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Collection", "Second")
.WithMany("LibraryLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Provider>", b =>
{
b.HasOne("Kyoo.Models.Library", "First")
.WithMany("ProviderLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", "Second")
.WithMany("LibraryLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Show>", b =>
{
b.HasOne("Kyoo.Models.Library", "First")
.WithMany("ShowLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Second")
.WithMany("LibraryLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Show, Kyoo.Models.Genre>", b =>
{
b.HasOne("Kyoo.Models.Show", "First")
.WithMany("GenreLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Genre", "Second")
.WithMany("ShowLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.HasOne("Kyoo.Models.Episode", "Episode")
.WithMany("ExternalIDs")
.HasForeignKey("EpisodeID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.People", "People")
.WithMany("ExternalIDs")
.HasForeignKey("PeopleID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Provider", "Provider")
.WithMany("MetadataLinks")
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Season", "Season")
.WithMany("ExternalIDs")
.HasForeignKey("SeasonID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Episode");
b.Navigation("People");
b.Navigation("Provider");
b.Navigation("Season");
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.PeopleRole", b =>
{
b.HasOne("Kyoo.Models.People", "People")
.WithMany("Roles")
.HasForeignKey("PeopleID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("People")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("People");
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Seasons")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.HasOne("Kyoo.Models.Studio", "Studio")
.WithMany("Shows")
.HasForeignKey("StudioID");
b.Navigation("Studio");
});
modelBuilder.Entity("Kyoo.Models.Track", b =>
{
b.HasOne("Kyoo.Models.Episode", "Episode")
.WithMany("Tracks")
.HasForeignKey("EpisodeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Episode");
});
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Navigation("LibraryLinks");
b.Navigation("ShowLinks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Navigation("ExternalIDs");
b.Navigation("Tracks");
});
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Navigation("ShowLinks");
});
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Navigation("CollectionLinks");
b.Navigation("ProviderLinks");
b.Navigation("ShowLinks");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Navigation("ExternalIDs");
b.Navigation("Roles");
});
modelBuilder.Entity("Kyoo.Models.Provider", b =>
{
b.Navigation("LibraryLinks");
b.Navigation("MetadataLinks");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Navigation("Episodes");
b.Navigation("ExternalIDs");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Navigation("CollectionLinks");
b.Navigation("Episodes");
b.Navigation("ExternalIDs");
b.Navigation("GenreLinks");
b.Navigation("LibraryLinks");
b.Navigation("People");
b.Navigation("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Navigation("Shows");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,607 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:Enum:item_type", "show,movie,collection")
.Annotation("Npgsql:Enum:status", "finished,airing,planned,unknown")
.Annotation("Npgsql:Enum:stream_type", "unknown,video,audio,subtitle,attachment");
migrationBuilder.CreateTable(
name: "Collections",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
Poster = table.Column<string>(type: "text", nullable: true),
Overview = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Collections", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Genres",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Genres", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Libraries",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
Paths = table.Column<string[]>(type: "text[]", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Libraries", x => x.ID);
});
migrationBuilder.CreateTable(
name: "People",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
Poster = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_People", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Providers",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
Logo = table.Column<string>(type: "text", nullable: true),
LogoExtension = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Providers", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Studios",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Studios", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Link<Library, Collection>",
columns: table => new
{
FirstID = table.Column<int>(type: "integer", nullable: false),
SecondID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Link<Library, Collection>", x => new { x.FirstID, x.SecondID });
table.ForeignKey(
name: "FK_Link<Library, Collection>_Collections_SecondID",
column: x => x.SecondID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Link<Library, Collection>_Libraries_FirstID",
column: x => x.FirstID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Link<Library, Provider>",
columns: table => new
{
FirstID = table.Column<int>(type: "integer", nullable: false),
SecondID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Link<Library, Provider>", x => new { x.FirstID, x.SecondID });
table.ForeignKey(
name: "FK_Link<Library, Provider>_Libraries_FirstID",
column: x => x.FirstID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Link<Library, Provider>_Providers_SecondID",
column: x => x.SecondID,
principalTable: "Providers",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Shows",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slug = table.Column<string>(type: "text", nullable: false),
Title = table.Column<string>(type: "text", nullable: true),
Aliases = table.Column<string[]>(type: "text[]", nullable: true),
Path = table.Column<string>(type: "text", nullable: true),
Overview = table.Column<string>(type: "text", nullable: true),
Status = table.Column<int>(type: "integer", nullable: true),
TrailerUrl = table.Column<string>(type: "text", nullable: true),
StartYear = table.Column<int>(type: "integer", nullable: true),
EndYear = table.Column<int>(type: "integer", nullable: true),
Poster = table.Column<string>(type: "text", nullable: true),
Logo = table.Column<string>(type: "text", nullable: true),
Backdrop = table.Column<string>(type: "text", nullable: true),
IsMovie = table.Column<bool>(type: "boolean", nullable: false),
StudioID = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Shows", x => x.ID);
table.ForeignKey(
name: "FK_Shows_Studios_StudioID",
column: x => x.StudioID,
principalTable: "Studios",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Link<Collection, Show>",
columns: table => new
{
FirstID = table.Column<int>(type: "integer", nullable: false),
SecondID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Link<Collection, Show>", x => new { x.FirstID, x.SecondID });
table.ForeignKey(
name: "FK_Link<Collection, Show>_Collections_FirstID",
column: x => x.FirstID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Link<Collection, Show>_Shows_SecondID",
column: x => x.SecondID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Link<Library, Show>",
columns: table => new
{
FirstID = table.Column<int>(type: "integer", nullable: false),
SecondID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Link<Library, Show>", x => new { x.FirstID, x.SecondID });
table.ForeignKey(
name: "FK_Link<Library, Show>_Libraries_FirstID",
column: x => x.FirstID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Link<Library, Show>_Shows_SecondID",
column: x => x.SecondID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Link<Show, Genre>",
columns: table => new
{
FirstID = table.Column<int>(type: "integer", nullable: false),
SecondID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Link<Show, Genre>", x => new { x.FirstID, x.SecondID });
table.ForeignKey(
name: "FK_Link<Show, Genre>_Genres_SecondID",
column: x => x.SecondID,
principalTable: "Genres",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Link<Show, Genre>_Shows_FirstID",
column: x => x.FirstID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PeopleRoles",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PeopleID = table.Column<int>(type: "integer", nullable: false),
ShowID = table.Column<int>(type: "integer", nullable: false),
Role = table.Column<string>(type: "text", nullable: true),
Type = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PeopleRoles", x => x.ID);
table.ForeignKey(
name: "FK_PeopleRoles_People_PeopleID",
column: x => x.PeopleID,
principalTable: "People",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PeopleRoles_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Seasons",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShowID = table.Column<int>(type: "integer", nullable: false),
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
Title = table.Column<string>(type: "text", nullable: true),
Overview = table.Column<string>(type: "text", nullable: true),
Year = table.Column<int>(type: "integer", nullable: true),
Poster = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Seasons", x => x.ID);
table.ForeignKey(
name: "FK_Seasons_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Episodes",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShowID = table.Column<int>(type: "integer", nullable: false),
SeasonID = table.Column<int>(type: "integer", nullable: true),
SeasonNumber = table.Column<int>(type: "integer", nullable: false),
EpisodeNumber = table.Column<int>(type: "integer", nullable: false),
AbsoluteNumber = table.Column<int>(type: "integer", nullable: false),
Path = table.Column<string>(type: "text", nullable: true),
Thumb = table.Column<string>(type: "text", nullable: true),
Title = table.Column<string>(type: "text", nullable: true),
Overview = table.Column<string>(type: "text", nullable: true),
ReleaseDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
Runtime = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Episodes", x => x.ID);
table.ForeignKey(
name: "FK_Episodes_Seasons_SeasonID",
column: x => x.SeasonID,
principalTable: "Seasons",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Episodes_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MetadataIds",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProviderID = table.Column<int>(type: "integer", nullable: false),
ShowID = table.Column<int>(type: "integer", nullable: true),
EpisodeID = table.Column<int>(type: "integer", nullable: true),
SeasonID = table.Column<int>(type: "integer", nullable: true),
PeopleID = table.Column<int>(type: "integer", nullable: true),
DataID = table.Column<string>(type: "text", nullable: true),
Link = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MetadataIds", x => x.ID);
table.ForeignKey(
name: "FK_MetadataIds_Episodes_EpisodeID",
column: x => x.EpisodeID,
principalTable: "Episodes",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MetadataIds_People_PeopleID",
column: x => x.PeopleID,
principalTable: "People",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MetadataIds_Providers_ProviderID",
column: x => x.ProviderID,
principalTable: "Providers",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MetadataIds_Seasons_SeasonID",
column: x => x.SeasonID,
principalTable: "Seasons",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MetadataIds_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Tracks",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
EpisodeID = table.Column<int>(type: "integer", nullable: false),
TrackIndex = table.Column<int>(type: "integer", nullable: false),
IsDefault = table.Column<bool>(type: "boolean", nullable: false),
IsForced = table.Column<bool>(type: "boolean", nullable: false),
IsExternal = table.Column<bool>(type: "boolean", nullable: false),
Title = table.Column<string>(type: "text", nullable: true),
Language = table.Column<string>(type: "text", nullable: true),
Codec = table.Column<string>(type: "text", nullable: true),
Path = table.Column<string>(type: "text", nullable: true),
Type = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tracks", x => x.ID);
table.ForeignKey(
name: "FK_Tracks_Episodes_EpisodeID",
column: x => x.EpisodeID,
principalTable: "Episodes",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Collections_Slug",
table: "Collections",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Episodes_SeasonID",
table: "Episodes",
column: "SeasonID");
migrationBuilder.CreateIndex(
name: "IX_Episodes_ShowID_SeasonNumber_EpisodeNumber_AbsoluteNumber",
table: "Episodes",
columns: new[] { "ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Genres_Slug",
table: "Genres",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Libraries_Slug",
table: "Libraries",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Link<Collection, Show>_SecondID",
table: "Link<Collection, Show>",
column: "SecondID");
migrationBuilder.CreateIndex(
name: "IX_Link<Library, Collection>_SecondID",
table: "Link<Library, Collection>",
column: "SecondID");
migrationBuilder.CreateIndex(
name: "IX_Link<Library, Provider>_SecondID",
table: "Link<Library, Provider>",
column: "SecondID");
migrationBuilder.CreateIndex(
name: "IX_Link<Library, Show>_SecondID",
table: "Link<Library, Show>",
column: "SecondID");
migrationBuilder.CreateIndex(
name: "IX_Link<Show, Genre>_SecondID",
table: "Link<Show, Genre>",
column: "SecondID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_EpisodeID",
table: "MetadataIds",
column: "EpisodeID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_PeopleID",
table: "MetadataIds",
column: "PeopleID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_ProviderID",
table: "MetadataIds",
column: "ProviderID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_SeasonID",
table: "MetadataIds",
column: "SeasonID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_ShowID",
table: "MetadataIds",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_People_Slug",
table: "People",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_PeopleRoles_PeopleID",
table: "PeopleRoles",
column: "PeopleID");
migrationBuilder.CreateIndex(
name: "IX_PeopleRoles_ShowID",
table: "PeopleRoles",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_Providers_Slug",
table: "Providers",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Seasons_ShowID_SeasonNumber",
table: "Seasons",
columns: new[] { "ShowID", "SeasonNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Shows_Slug",
table: "Shows",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Shows_StudioID",
table: "Shows",
column: "StudioID");
migrationBuilder.CreateIndex(
name: "IX_Studios_Slug",
table: "Studios",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Tracks_EpisodeID_Type_Language_TrackIndex_IsForced",
table: "Tracks",
columns: new[] { "EpisodeID", "Type", "Language", "TrackIndex", "IsForced" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Link<Collection, Show>");
migrationBuilder.DropTable(
name: "Link<Library, Collection>");
migrationBuilder.DropTable(
name: "Link<Library, Provider>");
migrationBuilder.DropTable(
name: "Link<Library, Show>");
migrationBuilder.DropTable(
name: "Link<Show, Genre>");
migrationBuilder.DropTable(
name: "MetadataIds");
migrationBuilder.DropTable(
name: "PeopleRoles");
migrationBuilder.DropTable(
name: "Tracks");
migrationBuilder.DropTable(
name: "Collections");
migrationBuilder.DropTable(
name: "Libraries");
migrationBuilder.DropTable(
name: "Genres");
migrationBuilder.DropTable(
name: "Providers");
migrationBuilder.DropTable(
name: "People");
migrationBuilder.DropTable(
name: "Episodes");
migrationBuilder.DropTable(
name: "Seasons");
migrationBuilder.DropTable(
name: "Shows");
migrationBuilder.DropTable(
name: "Studios");
}
}
}

View File

@ -1,783 +0,0 @@
// <auto-generated />
using System;
using Kyoo;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
[DbContext(typeof(DatabaseContext))]
partial class DatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasPostgresEnum(null, "item_type", new[] { "show", "movie", "collection" })
.HasPostgresEnum(null, "status", new[] { "finished", "airing", "planned", "unknown" })
.HasPostgresEnum(null, "stream_type", new[] { "unknown", "video", "audio", "subtitle", "attachment" })
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Collections");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("AbsoluteNumber")
.HasColumnType("integer");
b.Property<int>("EpisodeNumber")
.HasColumnType("integer");
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Path")
.HasColumnType("text");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp without time zone");
b.Property<int>("Runtime")
.HasColumnType("integer");
b.Property<int?>("SeasonID")
.HasColumnType("integer");
b.Property<int>("SeasonNumber")
.HasColumnType("integer");
b.Property<int>("ShowID")
.HasColumnType("integer");
b.Property<string>("Thumb")
.HasColumnType("text");
b.Property<string>("Title")
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("SeasonID");
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
b.ToTable("Episodes");
});
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Genres");
});
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string[]>("Paths")
.HasColumnType("text[]");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Libraries");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Collection, Kyoo.Models.Show>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Collection, Show>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Collection>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Library, Collection>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Provider>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Library, Provider>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Show>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Library, Show>");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Show, Kyoo.Models.Genre>", b =>
{
b.Property<int>("FirstID")
.HasColumnType("integer");
b.Property<int>("SecondID")
.HasColumnType("integer");
b.HasKey("FirstID", "SecondID");
b.HasIndex("SecondID");
b.ToTable("Link<Show, Genre>");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("DataID")
.HasColumnType("text");
b.Property<int?>("EpisodeID")
.HasColumnType("integer");
b.Property<string>("Link")
.HasColumnType("text");
b.Property<int?>("PeopleID")
.HasColumnType("integer");
b.Property<int>("ProviderID")
.HasColumnType("integer");
b.Property<int?>("SeasonID")
.HasColumnType("integer");
b.Property<int?>("ShowID")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("EpisodeID");
b.HasIndex("PeopleID");
b.HasIndex("ProviderID");
b.HasIndex("SeasonID");
b.HasIndex("ShowID");
b.ToTable("MetadataIds");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("People");
});
modelBuilder.Entity("Kyoo.Models.PeopleRole", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("PeopleID")
.HasColumnType("integer");
b.Property<string>("Role")
.HasColumnType("text");
b.Property<int>("ShowID")
.HasColumnType("integer");
b.Property<string>("Type")
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("PeopleID");
b.HasIndex("ShowID");
b.ToTable("PeopleRoles");
});
modelBuilder.Entity("Kyoo.Models.Provider", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Logo")
.HasColumnType("text");
b.Property<string>("LogoExtension")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Providers");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<int>("SeasonNumber")
.HasColumnType("integer");
b.Property<int>("ShowID")
.HasColumnType("integer");
b.Property<string>("Title")
.HasColumnType("text");
b.Property<int?>("Year")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
b.ToTable("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string[]>("Aliases")
.HasColumnType("text[]");
b.Property<string>("Backdrop")
.HasColumnType("text");
b.Property<int?>("EndYear")
.HasColumnType("integer");
b.Property<bool>("IsMovie")
.HasColumnType("boolean");
b.Property<string>("Logo")
.HasColumnType("text");
b.Property<string>("Overview")
.HasColumnType("text");
b.Property<string>("Path")
.HasColumnType("text");
b.Property<string>("Poster")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("StartYear")
.HasColumnType("integer");
b.Property<int?>("Status")
.HasColumnType("integer");
b.Property<int?>("StudioID")
.HasColumnType("integer");
b.Property<string>("Title")
.HasColumnType("text");
b.Property<string>("TrailerUrl")
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("StudioID");
b.ToTable("Shows");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Studios");
});
modelBuilder.Entity("Kyoo.Models.Track", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Codec")
.HasColumnType("text");
b.Property<int>("EpisodeID")
.HasColumnType("integer");
b.Property<bool>("IsDefault")
.HasColumnType("boolean");
b.Property<bool>("IsExternal")
.HasColumnType("boolean");
b.Property<bool>("IsForced")
.HasColumnType("boolean");
b.Property<string>("Language")
.HasColumnType("text");
b.Property<string>("Path")
.HasColumnType("text");
b.Property<string>("Title")
.HasColumnType("text");
b.Property<int>("TrackIndex")
.HasColumnType("integer");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();
b.ToTable("Tracks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.HasOne("Kyoo.Models.Season", "Season")
.WithMany("Episodes")
.HasForeignKey("SeasonID");
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Episodes")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Season");
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Collection, Kyoo.Models.Show>", b =>
{
b.HasOne("Kyoo.Models.Collection", "First")
.WithMany("ShowLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Second")
.WithMany("CollectionLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Collection>", b =>
{
b.HasOne("Kyoo.Models.Library", "First")
.WithMany("CollectionLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Collection", "Second")
.WithMany("LibraryLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Provider>", b =>
{
b.HasOne("Kyoo.Models.Library", "First")
.WithMany("ProviderLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Provider", "Second")
.WithMany("LibraryLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Library, Kyoo.Models.Show>", b =>
{
b.HasOne("Kyoo.Models.Library", "First")
.WithMany("ShowLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Second")
.WithMany("LibraryLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.Link<Kyoo.Models.Show, Kyoo.Models.Genre>", b =>
{
b.HasOne("Kyoo.Models.Show", "First")
.WithMany("GenreLinks")
.HasForeignKey("FirstID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Genre", "Second")
.WithMany("ShowLinks")
.HasForeignKey("SecondID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("First");
b.Navigation("Second");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.HasOne("Kyoo.Models.Episode", "Episode")
.WithMany("ExternalIDs")
.HasForeignKey("EpisodeID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.People", "People")
.WithMany("ExternalIDs")
.HasForeignKey("PeopleID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Provider", "Provider")
.WithMany("MetadataLinks")
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Season", "Season")
.WithMany("ExternalIDs")
.HasForeignKey("SeasonID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Episode");
b.Navigation("People");
b.Navigation("Provider");
b.Navigation("Season");
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.PeopleRole", b =>
{
b.HasOne("Kyoo.Models.People", "People")
.WithMany("Roles")
.HasForeignKey("PeopleID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("People")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("People");
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Seasons")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.HasOne("Kyoo.Models.Studio", "Studio")
.WithMany("Shows")
.HasForeignKey("StudioID");
b.Navigation("Studio");
});
modelBuilder.Entity("Kyoo.Models.Track", b =>
{
b.HasOne("Kyoo.Models.Episode", "Episode")
.WithMany("Tracks")
.HasForeignKey("EpisodeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Episode");
});
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Navigation("LibraryLinks");
b.Navigation("ShowLinks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Navigation("ExternalIDs");
b.Navigation("Tracks");
});
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Navigation("ShowLinks");
});
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Navigation("CollectionLinks");
b.Navigation("ProviderLinks");
b.Navigation("ShowLinks");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Navigation("ExternalIDs");
b.Navigation("Roles");
});
modelBuilder.Entity("Kyoo.Models.Provider", b =>
{
b.Navigation("LibraryLinks");
b.Navigation("MetadataLinks");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Navigation("Episodes");
b.Navigation("ExternalIDs");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Navigation("CollectionLinks");
b.Navigation("Episodes");
b.Navigation("ExternalIDs");
b.Navigation("GenreLinks");
b.Navigation("LibraryLinks");
b.Navigation("People");
b.Navigation("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Navigation("Shows");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -21,6 +21,7 @@ using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Unity;
using Unity.Lifetime;
namespace Kyoo
{
@ -147,46 +148,11 @@ namespace Kyoo
AllowedOrigins = { new Uri(publicUrl).GetLeftPart(UriPartial.Authority) }
});
// TODO Add custom method to the service container and expose those methods to the plugin
// TODO Add for example a AddRepository that will automatically register the complex interface, the IRepository<T> and the IBaseRepository
services.AddScoped<IBaseRepository, LibraryRepository>();
services.AddScoped<IBaseRepository, LibraryItemRepository>();
services.AddScoped<IBaseRepository, CollectionRepository>();
services.AddScoped<IBaseRepository, ShowRepository>();
services.AddScoped<IBaseRepository, SeasonRepository>();
services.AddScoped<IBaseRepository, EpisodeRepository>();
services.AddScoped<IBaseRepository, TrackRepository>();
services.AddScoped<IBaseRepository, PeopleRepository>();
services.AddScoped<IBaseRepository, StudioRepository>();
services.AddScoped<IBaseRepository, GenreRepository>();
services.AddScoped<IBaseRepository, ProviderRepository>();
services.AddScoped<ILibraryRepository, LibraryRepository>();
services.AddScoped<ILibraryItemRepository, LibraryItemRepository>();
services.AddScoped<ICollectionRepository, CollectionRepository>();
services.AddScoped<IShowRepository, ShowRepository>();
services.AddScoped<ISeasonRepository, SeasonRepository>();
services.AddScoped<IEpisodeRepository, EpisodeRepository>();
services.AddScoped<ITrackRepository, TrackRepository>();
services.AddScoped<IPeopleRepository, PeopleRepository>();
services.AddScoped<IStudioRepository, StudioRepository>();
services.AddScoped<IGenreRepository, GenreRepository>();
services.AddScoped<IProviderRepository, ProviderRepository>();
services.AddScoped<DbContext, DatabaseContext>();
services.AddScoped<ILibraryManager, LibraryManager>();
services.AddSingleton<IFileManager, FileManager>();
services.AddSingleton<ITranscoder, Transcoder>();
services.AddSingleton<IThumbnailsManager, ThumbnailsManager>();
services.AddSingleton<IProviderManager, ProviderManager>();
services.AddSingleton<IPluginManager, PluginManager>();
services.AddSingleton<ITaskManager, TaskManager>();
services.AddHostedService(provider => (TaskManager)provider.GetService<ITaskManager>());
services.AddScoped<DbContext, DatabaseContext>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IUnityContainer container)
public void Configure(IUnityContainer container, IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
@ -249,8 +215,10 @@ namespace Kyoo
spa.UseAngularCliServer("start");
});
CoreModule.Configure(container);
container.Resolve<ITaskManager>().ReloadTasks();
new CoreModule().Configure(container, _configuration, app, env.IsDevelopment());
container.RegisterFactory<IHostedService>(c => c.Resolve<ITaskManager>(), new SingletonLifetimeManager());
// TODO the reload should re inject components from the constructor.
// TODO fin a way to inject tasks without a IUnityContainer.
}
}
}

View File

@ -7,11 +7,12 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Kyoo.Controllers;
using Kyoo.Models.Attributes;
using Kyoo.Models.Exceptions;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
namespace Kyoo.Tasks
{
public class Crawler : ITask
{