mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-30 04:18:27 +01:00
Added pgsql support for jellyfin 🎉
This commit is contained in:
1624
Jellyfin.Database/Jellyfin.Database.Providers.PgSql/Migrations/20250127174201_InitMigration.Designer.cs
generated
Normal file
1624
Jellyfin.Database/Jellyfin.Database.Providers.PgSql/Migrations/20250127174201_InitMigration.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
using Jellyfin.Database.Providers.SqLite;
|
||||
using Jellyfin.Server.Implementations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Jellyfin.Database.Providers.PgSql
|
||||
{
|
||||
/// <summary>
|
||||
/// The design time factory for <see cref="JellyfinDbContext"/>.
|
||||
/// This is only used for the creation of migrations and not during runtime.
|
||||
/// </summary>
|
||||
internal sealed class PgSqlDesignTimeJellyfinDbFactory : IDesignTimeDbContextFactory<JellyfinDbContext>
|
||||
{
|
||||
public JellyfinDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<JellyfinDbContext>();
|
||||
optionsBuilder.UseNpgsql(f => f.MigrationsAssembly(GetType().Assembly));
|
||||
|
||||
return new JellyfinDbContext(
|
||||
optionsBuilder.Options,
|
||||
NullLogger<JellyfinDbContext>.Instance,
|
||||
new SqliteDatabaseProvider(null!, NullLogger<SqliteDatabaseProvider>.Instance));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using Jellyfin.Server.Implementations;
|
||||
using Jellyfin.Server.Implementations.DatabaseConfiguration;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npgsql;
|
||||
|
||||
namespace Jellyfin.Database.Providers.PgSql;
|
||||
|
||||
/// <summary>
|
||||
/// Configures jellyfin to use an SqLite database.
|
||||
/// </summary>
|
||||
[JellyfinDatabaseProviderKey("Jellyfin-PgSql")]
|
||||
public sealed class PgSqlDatabaseProvider : IJellyfinDatabaseProvider
|
||||
{
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly ILogger<PgSqlDatabaseProvider> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PgSqlDatabaseProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="configurationManager">Configuration manager to get PgSQL connection data.</param>
|
||||
/// <param name="logger">A logger.</param>
|
||||
public PgSqlDatabaseProvider(IConfigurationManager configurationManager, ILogger<PgSqlDatabaseProvider> logger)
|
||||
{
|
||||
_configurationManager = configurationManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IDbContextFactory<JellyfinDbContext>? DbContextFactory { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Initialise(DbContextOptionsBuilder options)
|
||||
{
|
||||
var dbSettings = _configurationManager.GetConfiguration<DatabaseConfigurationOptions>("database");
|
||||
|
||||
if (dbSettings.PostgreSql is null)
|
||||
{
|
||||
throw new InvalidOperationException("Selected PgSQL as database provider but did not provide required configuration. Please see docs.");
|
||||
}
|
||||
|
||||
var connectionBuilder = new NpgsqlConnectionStringBuilder();
|
||||
connectionBuilder.ApplicationName = "jellyfin";
|
||||
connectionBuilder.CommandTimeout = dbSettings.PostgreSql.Timeout;
|
||||
connectionBuilder.Database = dbSettings.PostgreSql.DatabaseName;
|
||||
connectionBuilder.Username = dbSettings.PostgreSql.Username;
|
||||
connectionBuilder.Password = dbSettings.PostgreSql.Password;
|
||||
connectionBuilder.Host = dbSettings.PostgreSql.ServerName;
|
||||
connectionBuilder.Port = dbSettings.PostgreSql.Port;
|
||||
|
||||
var connectionString = connectionBuilder.ToString();
|
||||
|
||||
options
|
||||
.UseNpgsql(connectionString, pgSqlOptions => pgSqlOptions.MigrationsAssembly(GetType().Assembly));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task RunScheduledOptimisation(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
/// The design time factory for <see cref="JellyfinDbContext"/>.
|
||||
/// This is only used for the creation of migrations and not during runtime.
|
||||
/// </summary>
|
||||
internal sealed class DesignTimeJellyfinDbFactory : IDesignTimeDbContextFactory<JellyfinDbContext>
|
||||
internal sealed class SqliteDesignTimeJellyfinDbFactory : IDesignTimeDbContextFactory<JellyfinDbContext>
|
||||
{
|
||||
public JellyfinDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
Reference in New Issue
Block a user