diff --git a/back/src/Kyoo.Host/Application.cs b/back/src/Kyoo.Host/Application.cs
index 2647e758..0d090919 100644
--- a/back/src/Kyoo.Host/Application.cs
+++ b/back/src/Kyoo.Host/Application.cs
@@ -103,7 +103,6 @@ public class Application
await using (AsyncServiceScope scope = host.Services.CreateAsyncScope())
{
- PostgresModule.Initialize(scope.ServiceProvider);
await MeilisearchModule.Initialize(scope.ServiceProvider);
}
diff --git a/back/src/Kyoo.Postgresql/PostgresModule.cs b/back/src/Kyoo.Postgresql/PostgresModule.cs
index e3286c9b..56c65264 100644
--- a/back/src/Kyoo.Postgresql/PostgresModule.cs
+++ b/back/src/Kyoo.Postgresql/PostgresModule.cs
@@ -38,45 +38,13 @@ namespace Kyoo.Postgresql;
///
/// A module to add postgresql capacity to the app.
///
-public class PostgresModule : IPlugin
+public class PostgresModule(IConfiguration configuration, IWebHostEnvironment environment) : IPlugin
{
///
public string Name => "Postgresql";
- ///
- /// The configuration to use. The database connection string is pulled from it.
- ///
- private readonly IConfiguration _configuration;
-
- ///
- /// The host environment to check if the app is in debug mode.
- ///
- private readonly IWebHostEnvironment _environment;
-
- ///
- /// Create a new postgres module instance and use the given configuration and environment.
- ///
- /// The configuration to use
- /// The environment that will be used (if the env is in development mode, more information will be displayed on errors.
- public PostgresModule(IConfiguration configuration, IWebHostEnvironment env)
+ static PostgresModule()
{
- _configuration = configuration;
- _environment = env;
- }
-
- ///
- /// Migrate the database.
- ///
- /// The service list to retrieve the database context
- public static void Initialize(IServiceProvider provider)
- {
- DatabaseContext context = provider.GetRequiredService();
- context.Database.Migrate();
-
- using NpgsqlConnection conn = (NpgsqlConnection)context.Database.GetDbConnection();
- conn.Open();
- conn.ReloadTypes();
-
SqlMapper.TypeMapProvider = (type) =>
{
return new CustomPropertyTypeMap(
@@ -118,11 +86,11 @@ public class PostgresModule : IPlugin
DbConnectionStringBuilder builder =
new()
{
- ["USER ID"] = _configuration.GetValue("POSTGRES_USER", "KyooUser"),
- ["PASSWORD"] = _configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
- ["SERVER"] = _configuration.GetValue("POSTGRES_SERVER", "db"),
- ["PORT"] = _configuration.GetValue("POSTGRES_PORT", "5432"),
- ["DATABASE"] = _configuration.GetValue("POSTGRES_DB", "kyooDB"),
+ ["USER ID"] = configuration.GetValue("POSTGRES_USER", "KyooUser"),
+ ["PASSWORD"] = configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
+ ["SERVER"] = configuration.GetValue("POSTGRES_SERVER", "db"),
+ ["PORT"] = configuration.GetValue("POSTGRES_PORT", "5432"),
+ ["DATABASE"] = configuration.GetValue("POSTGRES_DB", "kyooDB"),
["POOLING"] = "true",
["MAXPOOLSIZE"] = "95",
["TIMEOUT"] = "30"
@@ -132,7 +100,7 @@ public class PostgresModule : IPlugin
x =>
{
x.UseNpgsql(builder.ConnectionString).UseProjectables();
- if (_environment.IsDevelopment())
+ if (environment.IsDevelopment())
x.EnableDetailedErrors().EnableSensitiveDataLogging();
},
ServiceLifetime.Transient