Remove postgres migrations handled by the api

This commit is contained in:
Zoe Roux 2024-03-25 22:24:00 +01:00
parent 928bfe7876
commit fb1c006cd9
No known key found for this signature in database
2 changed files with 8 additions and 41 deletions

View File

@ -103,7 +103,6 @@ public class Application
await using (AsyncServiceScope scope = host.Services.CreateAsyncScope())
{
PostgresModule.Initialize(scope.ServiceProvider);
await MeilisearchModule.Initialize(scope.ServiceProvider);
}

View File

@ -38,45 +38,13 @@ namespace Kyoo.Postgresql;
/// <summary>
/// A module to add postgresql capacity to the app.
/// </summary>
public class PostgresModule : IPlugin
public class PostgresModule(IConfiguration configuration, IWebHostEnvironment environment) : IPlugin
{
/// <inheritdoc />
public string Name => "Postgresql";
/// <summary>
/// The configuration to use. The database connection string is pulled from it.
/// </summary>
private readonly IConfiguration _configuration;
/// <summary>
/// The host environment to check if the app is in debug mode.
/// </summary>
private readonly IWebHostEnvironment _environment;
/// <summary>
/// Create a new postgres module instance and use the given configuration and environment.
/// </summary>
/// <param name="configuration">The configuration to use</param>
/// <param name="env">The environment that will be used (if the env is in development mode, more information will be displayed on errors.</param>
public PostgresModule(IConfiguration configuration, IWebHostEnvironment env)
static PostgresModule()
{
_configuration = configuration;
_environment = env;
}
/// <summary>
/// Migrate the database.
/// </summary>
/// <param name="provider">The service list to retrieve the database context</param>
public static void Initialize(IServiceProvider provider)
{
DatabaseContext context = provider.GetRequiredService<DatabaseContext>();
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