mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Remove postgres migrations handled by the api
This commit is contained in:
parent
928bfe7876
commit
fb1c006cd9
@ -103,7 +103,6 @@ public class Application
|
|||||||
|
|
||||||
await using (AsyncServiceScope scope = host.Services.CreateAsyncScope())
|
await using (AsyncServiceScope scope = host.Services.CreateAsyncScope())
|
||||||
{
|
{
|
||||||
PostgresModule.Initialize(scope.ServiceProvider);
|
|
||||||
await MeilisearchModule.Initialize(scope.ServiceProvider);
|
await MeilisearchModule.Initialize(scope.ServiceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,45 +38,13 @@ namespace Kyoo.Postgresql;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A module to add postgresql capacity to the app.
|
/// A module to add postgresql capacity to the app.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PostgresModule : IPlugin
|
public class PostgresModule(IConfiguration configuration, IWebHostEnvironment environment) : IPlugin
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "Postgresql";
|
public string Name => "Postgresql";
|
||||||
|
|
||||||
/// <summary>
|
static PostgresModule()
|
||||||
/// 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)
|
|
||||||
{
|
{
|
||||||
_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) =>
|
SqlMapper.TypeMapProvider = (type) =>
|
||||||
{
|
{
|
||||||
return new CustomPropertyTypeMap(
|
return new CustomPropertyTypeMap(
|
||||||
@ -118,11 +86,11 @@ public class PostgresModule : IPlugin
|
|||||||
DbConnectionStringBuilder builder =
|
DbConnectionStringBuilder builder =
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
["USER ID"] = _configuration.GetValue("POSTGRES_USER", "KyooUser"),
|
["USER ID"] = configuration.GetValue("POSTGRES_USER", "KyooUser"),
|
||||||
["PASSWORD"] = _configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
|
["PASSWORD"] = configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
|
||||||
["SERVER"] = _configuration.GetValue("POSTGRES_SERVER", "db"),
|
["SERVER"] = configuration.GetValue("POSTGRES_SERVER", "db"),
|
||||||
["PORT"] = _configuration.GetValue("POSTGRES_PORT", "5432"),
|
["PORT"] = configuration.GetValue("POSTGRES_PORT", "5432"),
|
||||||
["DATABASE"] = _configuration.GetValue("POSTGRES_DB", "kyooDB"),
|
["DATABASE"] = configuration.GetValue("POSTGRES_DB", "kyooDB"),
|
||||||
["POOLING"] = "true",
|
["POOLING"] = "true",
|
||||||
["MAXPOOLSIZE"] = "95",
|
["MAXPOOLSIZE"] = "95",
|
||||||
["TIMEOUT"] = "30"
|
["TIMEOUT"] = "30"
|
||||||
@ -132,7 +100,7 @@ public class PostgresModule : IPlugin
|
|||||||
x =>
|
x =>
|
||||||
{
|
{
|
||||||
x.UseNpgsql(builder.ConnectionString).UseProjectables();
|
x.UseNpgsql(builder.ConnectionString).UseProjectables();
|
||||||
if (_environment.IsDevelopment())
|
if (environment.IsDevelopment())
|
||||||
x.EnableDetailedErrors().EnableSensitiveDataLogging();
|
x.EnableDetailedErrors().EnableSensitiveDataLogging();
|
||||||
},
|
},
|
||||||
ServiceLifetime.Transient
|
ServiceLifetime.Transient
|
||||||
|
Loading…
x
Reference in New Issue
Block a user