mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-30 19:35:24 -04:00
Added pgsql support for jellyfin 🎉
This commit is contained in:
+1624
File diff suppressed because it is too large
Load Diff
+1104
File diff suppressed because it is too large
Load Diff
+1621
File diff suppressed because it is too large
Load Diff
+26
@@ -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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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)
|
||||
{
|
||||
@@ -11,4 +11,9 @@ public class DatabaseConfigurationOptions
|
||||
/// Gets or Sets the type of database jellyfin should use.
|
||||
/// </summary>
|
||||
public required string DatabaseType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the settings to run jellyfin with Postgres.
|
||||
/// </summary>
|
||||
public PostgreSqlOptions? PostgreSql { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.DatabaseConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// Options specific to run jellyfin on a postgreSql database.
|
||||
/// </summary>
|
||||
public class PostgreSqlOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or Sets the Port. Defaults to 5432.
|
||||
/// </summary>
|
||||
public required int Port { get; set; } = 5432;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the Server name.
|
||||
/// </summary>
|
||||
public required string ServerName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the username.
|
||||
/// </summary>
|
||||
public required string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the password.
|
||||
/// </summary>
|
||||
public required string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the database name. Defaults to "Jellyfin".
|
||||
/// </summary>
|
||||
public string DatabaseName { get; set; } = "Jellyfin";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the timeout in secounds before a running command is terminated. Defaults to 30.
|
||||
/// </summary>
|
||||
public int Timeout { get; set; } = 30;
|
||||
}
|
||||
Reference in New Issue
Block a user