PgSqlDesignTimeJellyfinDbFactory.cs 1011 B

12345678910111213141516171819202122232425
  1. using Jellyfin.Server.Implementations;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Design;
  4. using Microsoft.Extensions.Logging.Abstractions;
  5. namespace Jellyfin.Database.Providers.PgSql
  6. {
  7. /// <summary>
  8. /// The design time factory for <see cref="JellyfinDbContext"/>.
  9. /// This is only used for the creation of migrations and not during runtime.
  10. /// </summary>
  11. internal sealed class PgSqlDesignTimeJellyfinDbFactory : IDesignTimeDbContextFactory<JellyfinDbContext>
  12. {
  13. public JellyfinDbContext CreateDbContext(string[] args)
  14. {
  15. var optionsBuilder = new DbContextOptionsBuilder<JellyfinDbContext>();
  16. optionsBuilder.UseNpgsql(f => f.MigrationsAssembly(GetType().Assembly));
  17. return new JellyfinDbContext(
  18. optionsBuilder.Options,
  19. NullLogger<JellyfinDbContext>.Instance,
  20. new PgSqlDatabaseProvider(null!, NullLogger<PgSqlDatabaseProvider>.Instance));
  21. }
  22. }
  23. }